﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using XML_VML.Object;

namespace XML_VML
{
    public partial class MainWindow : Window
    {
        static int MinPoint = -100000;
        static int MaxPoint = 100000;
        static Color ErrorColor = (Color)ColorConverter.ConvertFromString("#FFFBE1D7");
        static Color TrueColor = Colors.White;

        SolidColorBrush ErrorBrush = new SolidColorBrush(ErrorColor);
        SolidColorBrush TrueBrush = new SolidColorBrush(TrueColor);

        public List<VObject> root;
        private DesignerCanvas canvas = null;

        VObject Parent = null;
        VGroup parentGroup = null;
        int pos = 0;
        string[] pathPos;


        int numError = 0;

        public MainWindow()
        {
            InitializeComponent();

            canvas = (DesignerCanvas)FindName("MyDesignerCanvas");
            if(canvas != null)
            {
                canvas.SetParent(this);
            }else
            {
                MessageBox.Show("Khởi tạo canvas không thành công");
                return;
            }

            HideAllProperties();

            tbOpacity.ToolTip = "0.0 ≤ Opacity ≤ 1.0";
            tbCoordSize.ToolTip = "-100000 ≤ X,Y ≤ 100000";

            btnOutline.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6C13712A"));
            btnProperties.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6C13712A"));
        }

        #region User Interface

        private void btClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            e.Handled = true;
        }

        private void btMaximize_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = (WindowState == WindowState.Normal) ? WindowState.Maximized : WindowState.Normal;
            e.Handled = true;
        }

        private void btMinimize_Click(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
            e.Handled = true;
        }

        private void moveRectangle_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            if (Mouse.LeftButton == MouseButtonState.Pressed)
                DragMove();
        }

        #endregion User Interface

        #region Properties

        private void HideAllProperties()
        {
            pId.Visibility = pType.Visibility = pAdj.Visibility = pPath.Visibility = pHref.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility = pFill.Visibility = pFillColor.Visibility = pV.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility =
                pLimo.Visibility = pFillOk.Visibility = pStrokeOk.Visibility = pShadowOk.Visibility =
                pArrowOk.Visibility = pGradientShapeOk.Visibility = pTextBoxRect.Visibility =
                pTextPathOk.Visibility = pEqn.Visibility = pPosition.Visibility = pPolar.Visibility =
                pMap.Visibility = pInvX.Visibility = pInvY.Visibility = pSwitch.Visibility = pXRange.Visibility =
                pYRange.Visibility = pRadiusRange.Visibility = pOn.Visibility = pColor.Visibility =
                pColor2.Visibility = pSrc.Visibility = pSize.Visibility = pOrigin.Visibility =
                pAspect.Visibility = pAlignShape.Visibility = pColors.Visibility = pAngle.Visibility =
                pFocus.Visibility = pFocusSize.Visibility = pFocusPosition.Visibility = pMethod.Visibility =
                pWeight.Visibility = pStyle.Visibility = pMiterLimit.Visibility = pJoinStyle.Visibility =
                pEndCap.Visibility = pDashStyle.Visibility = pFillType.Visibility = pImageSize.Visibility =
                pImageAlignShape.Visibility = pStartArrow.Visibility = pStartArrowLength.Visibility =
                pStartArrowWidth.Visibility = pEndArrow.Visibility = pEndArrowLength.Visibility =
                pEndArrowWidth.Visibility = pObscured.Visibility = pOffset.Visibility = pOffset2.Visibility =
                pMatrix.Visibility = pFitShape.Visibility = pFitPath.Visibility = pTrim.Visibility =
                pXScale.Visibility = pString.Visibility = pCropBottom.Visibility = pCropLeft.Visibility =
                pCropRight.Visibility = pCropTop.Visibility = pGain.Visibility = pBlackLevel.Visibility =
                pGamma.Visibility = pGrayScale.Visibility = pBilevel.Visibility = pFrom.Visibility =
                pTo.Visibility = pPoints.Visibility = pControl1.Visibility = pControl2.Visibility =
                pArcSize.Visibility = pEndAngle.Visibility = pEmbossColor.Visibility = pStartAngle.Visibility
                = Visibility.Collapsed;
        }

        private void ShowProperty(VObject obj)
        {
            HideAllProperties();

            if (obj is VShape)
            {
                ShowProperty_VShape((VShape)obj);
            }
            else if (obj is VShapeType)
            {
                ShowProperty_VShapeType((VShapeType)obj);
            }
            else if (obj is VGroup)
            {
                ShowProperty_VGroup((VGroup)obj);
            }
            else if (obj is VBackground)
            {
                ShowProperty_VBackground((VBackground)obj);
            }
            else if (obj is VPath)
            {
                ShowProperty_VPath((VPath)obj);
            }
            else if (obj is VFormulas)
            {
                //nothing
            }
            else if (obj is VF)
            {
                ShowProperty_VF((VF)obj);
            }
            else if (obj is VHandles)
            {
                //nothing
            }
            else if (obj is VH)
            {
                ShowProperty_VH((VH)obj);
            }
            else if (obj is VFill)
            {
                ShowProperty_VFill((VFill)obj);
            }
            else if (obj is VStroke)
            {
                ShowProperty_VStroke((VStroke)obj);
            }
            else if (obj is VShadow)
            {
                ShowProperty_VShadow((VShadow)obj);
            }
            else if (obj is VTextBox)
            {
                ShowProperty_VTextBox((VTextBox)obj);
            }
            else if (obj is VTextPath)
            {
                ShowProperty_VTextPath((VTextPath)obj);
            }
            else if (obj is VImageData)
            {
                ShowProperty_VImageData((VImageData)obj);
            }
            else if (obj is VLine)
            {
                ShowProperty_VLine((VLine)obj);
            }
            else if (obj is VPolyLine)
            {
                ShowProperty_VPolyLine((VPolyLine)obj);
            }
            else if (obj is VCurve)
            {
                ShowProperty_VCurve((VCurve)obj);
            }
            else if (obj is VRect)
            {
                ShowProperty_VRect((VRect)obj);
            }
            else if (obj is VRoundRect)
            {
                ShowProperty_VRoundRect((VRoundRect)obj);
            }
            else if (obj is VOval)
            {
                ShowProperty_VOval((VOval)obj);
            }
            else if (obj is VArc)
            {
                ShowProperty_VArc((VArc)obj);
            }
            else if (obj is VImage)
            {
                ShowProperty_VImage((VImage)obj);
            }
        }

        private void ShowProperty_VShape(VShape shape)
        {
            tbId.Text = shape.Id;
            tbType.Text = shape.Type;
            tbStyle.Text = shape.Style;
            tbAdj.Text = shape.Adj;
            tbHref.Text = shape.Href;
            tbPath.Text = shape.Path;
            tbTarget.Text = shape.Target;
            tbClass.Text = shape.Class;
            tbTitle.Text = shape.Title;
            tbAlt.Text = shape.Alt;
            tbOpacity.Text = shape.Opacity.ToString();
            tbChromakey.Text = shape.Chromakey;
            tbStroke.Text = shape.Stroke.ToString();
            tbStrokeColor.Text = shape.StrokeColor;
            tbStrokeWeight.Text = shape.StrokeWeight.ToString();
            tbFill.Text = shape.Fill.ToString();
            tbFillColor.Text = shape.FillColor;
            tbV.Text = shape.V;
            tbPrint.Text = shape.Print.ToString();
            tbCoordOrigin.Text = shape.CoordOrigin.X + " " + shape.CoordOrigin.Y;
            tbCoordSize.Text = shape.CoordSize.X + " " + shape.CoordSize.Y;
            tbWrapCoords.Text = shape.WrapCoords;

            pId.Visibility = pType.Visibility = pAdj.Visibility = pPath.Visibility = pHref.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility = pFill.Visibility = pFillColor.Visibility = pV.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VShapeType(VShapeType shapeType)
        {
            tbId.Text = shapeType.Id;
            tbStyle.Text = shapeType.Style;
            tbAdj.Text = shapeType.Adj;
            tbHref.Text = shapeType.Href;
            tbPath.Text = shapeType.Path;
            tbTarget.Text = shapeType.Target;
            tbClass.Text = shapeType.Class;
            tbTitle.Text = shapeType.Title;
            tbAlt.Text = shapeType.Alt;
            tbOpacity.Text = shapeType.Opacity.ToString();
            tbChromakey.Text = shapeType.Chromakey;
            tbStroke.Text = shapeType.Stroke.ToString();
            tbStrokeColor.Text = shapeType.StrokeColor;
            tbStrokeWeight.Text = shapeType.StrokeWeight.ToString();
            tbFill.Text = shapeType.Fill.ToString();
            tbFillColor.Text = shapeType.FillColor;
            tbV.Text = shapeType.V;
            tbPrint.Text = shapeType.Print.ToString();
            tbCoordOrigin.Text = shapeType.CoordOrigin.X + " " + shapeType.CoordOrigin.Y;
            tbCoordSize.Text = shapeType.CoordSize.X + " " + shapeType.CoordSize.Y;
            tbWrapCoords.Text = shapeType.WrapCoords;

            pId.Visibility = pAdj.Visibility = pPath.Visibility = pHref.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility = pFill.Visibility = pFillColor.Visibility = pV.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VGroup(VGroup group)
        {
            tbId.Text = group.Id;
            tbStyle.Text = group.Style;
            tbHref.Text = group.Href;
            tbClass.Text = group.Class;
            tbTarget.Text = group.Target;
            tbTitle.Text = group.Title;
            tbAlt.Text = group.Alt;
            tbCoordOrigin.Text = group.CoordOrigin.X + " " + group.CoordOrigin.Y;
            tbCoordSize.Text = group.CoordSize.X + " " + group.CoordSize.Y;
            tbWrapCoords.Text = group.WrapCoords;

            pId.Visibility = pHref.Visibility = pClass.Visibility = pStyle.Visibility =
                pTarget.Visibility = pTitle.Visibility = pAlt.Visibility =
                pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VBackground(VBackground background)
        {
            tbId.Text = background.Id;
            tbFill.Text = background.Fill.ToString();
            tbFillColor.Text = background.FillColor;

            pId.Visibility = pFill.Visibility = pFillColor.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VPath(VPath path)
        {
            tbId.Text = path.Id;
            tbV.Text = path.V;
            tbLimo.Text = path.Limo.X + " " + path.Limo.Y;
            tbFillOk.Text = path.FillOk.ToString();
            tbStrokeOk.Text = path.StrokeOk.ToString();
            tbShadowOk.Text = path.ShadowOk.ToString();
            tbArrowOk.Text = path.ArrowOk.ToString();
            tbGradientShapeOk.Text = path.GradientShapeOK.ToString();
            tbTextPathOk.Text = path.TextPathOK.ToString();
            tbTextBoxRect.Text = path.TextBoxRect;

            pId.Visibility = pV.Visibility = pLimo.Visibility = pFillOk.Visibility = pStrokeOk.Visibility =
                pShadowOk.Visibility = pArrowOk.Visibility = pGradientShapeOk.Visibility = pTextPathOk.Visibility =
                pTextBoxRect.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VF(VF f)
        {
            tbEqn.Text = f.eqn;

            pEqn.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VH(VH h)
        {
            tbPosition.Text = h.Position.X + " " + h.Position.Y;
            
            if (h.Polar.X == int.MinValue && h.Polar.Y == int.MinValue)
            {
                tbPolar.Text = "auto";
            }
            else
            {
                tbPolar.Text = h.Polar.X + " " + h.Polar.Y;
            }

            tbMap.Text = h.Map.X + " " + h.Map.Y;
            tbInvX.Text = h.InvX.ToString();
            tbInvY.Text = h.InvY.ToString();
            tbSwitch.Text = h.Switch.ToString();
            tbXRange.Text = h.XRange.X + " " + h.XRange.Y;
            tbYRange.Text = h.YRange.X + " " + h.YRange.Y;
            tbRadiusRange.Text = h.RadiusRange.X + " " + h.RadiusRange.Y;

            pPosition.Visibility = pPolar.Visibility = pMap.Visibility = pInvX.Visibility = pInvY.Visibility =
                pSwitch.Visibility = pXRange.Visibility = pYRange.Visibility = pRadiusRange.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VFill(VFill fill)
        {
            tbId.Text = fill.Id;
            tbType.Text = fill.Type;
            tbOn.Text = fill.On.ToString();
            tbColor.Text = fill.Color;
            tbColor2.Text = fill.Color2;
            tbOpacity.Text = fill.Opacity.ToString();
            tbSrc.Text = fill.Src;

            if (fill.Size.X == int.MinValue && fill.Size.Y == int.MinValue)
            {
                tbSize.Text = "auto";
            }
            else
            {
                tbSize.Text = fill.Size.X + " " + fill.Size.Y;
            }

            if (fill.Origin.X == int.MinValue && fill.Origin.Y == int.MinValue)
            {
                tbOrigin.Text = "auto";
            }
            else
            {
                tbOrigin.Text = fill.Origin.X + " " + fill.Origin.Y;
            }

            if (fill.Position.X == int.MinValue && fill.Position.Y == int.MinValue)
            {
                tbPosition.Text = "auto";
            }
            else
            {
                tbPosition.Text = fill.Position.X + " " + fill.Position.Y;
            }

            tbAlignShape.Text = fill.AlignShape.ToString();
            tbColors.Text = fill.Colors;
            tbAngle.Text = fill.Angle.ToString();
            tbFocus.Text = fill.Focus.ToString();
            tbFocusSize.Text = fill.FocusSize.X + " " + fill.FocusSize.Y;
            tbFocusPosition.Text = fill.FocusPosition.X + " " + fill.FocusPosition.Y;
            tbMethod.Text = fill.Method;
            tbAspect.Text = fill.Aspect;

            pId.Visibility = pType.Visibility = pOn.Visibility = pColor.Visibility = pColor2.Visibility =
                pOpacity.Visibility = pSrc.Visibility = pSize.Visibility = pOrigin.Visibility = pPosition.Visibility =
                pAlignShape.Visibility = pColors.Visibility = pAngle.Visibility = pFocus.Visibility = pFocusPosition.Visibility =
                pFocusSize.Visibility = pMethod.Visibility = pAspect.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VStroke(VStroke stroke)
        {
            tbId.Text = stroke.Id;
            tbOn.Text = stroke.On.ToString();
            tbWeight.Text = stroke.Weight.ToString();
            tbColor.Text = stroke.Color;
            tbColor2.Text = stroke.Color2;
            tbOpacity.Text = stroke.Opacity.ToString();
            tbStyle.Text = stroke.Style;
            tbMiterLimit.Text = stroke.MiterLimit.ToString();
            tbJoinStyle.Text = stroke.JoinStyle;
            tbEndCap.Text = stroke.EndCap;
            tbDashStyle.Text = stroke.DashStyle;
            tbFillType.Text = stroke.FillType;
            tbSrc.Text = stroke.Src;

            if (stroke.ImageSize.X == int.MinValue && stroke.ImageSize.Y == int.MinValue)
            {
                tbImageSize.Text = "auto";
            }
            else
            {
                tbImageSize.Text = stroke.ImageSize.X + " " + stroke.ImageSize.Y;
            }

            tbImageAlignShape.Text = stroke.ImageAlignShape.ToString();
            tbStartArrow.Text = stroke.StartArrow;
            tbStartArrowLength.Text = stroke.StartArrowLength;
            tbStartArrowWidth.Text = stroke.StartArrowWidth;
            tbEndArrow.Text = stroke.EndArrow;
            tbEndArrowLength.Text = stroke.EndArrowLength;
            tbEndArrowWidth.Text = stroke.EndArrowWidth;

            pId.Visibility = pWeight.Visibility = pOn.Visibility = pColor.Visibility = pColor2.Visibility =
                pOpacity.Visibility = pStyle.Visibility = pMiterLimit.Visibility = pJoinStyle.Visibility =
                pEndCap.Visibility = pDashStyle.Visibility = pFillType.Visibility = pSrc.Visibility = pImageSize.Visibility =
                pImageAlignShape.Visibility = pStartArrow.Visibility = pStartArrowLength.Visibility = pStartArrowWidth.Visibility =
                pEndArrow.Visibility = pEndArrowLength.Visibility = pEndArrowWidth.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VShadow(VShadow shadow)
        {
            tbId.Text = shadow.Id;
            tbOn.Text = shadow.On.ToString();
            tbType.Text = shadow.Type;
            tbObscured.Text = shadow.Obscured.ToString();
            tbColor.Text = shadow.Color;
            tbOpacity.Text = shadow.Opacity.ToString();
            tbOffset.Text = shadow.Offset.X + " " + shadow.Offset.Y;
            tbColor2.Text = shadow.Color2;
            tbOffset2.Text = shadow.Offset2.X + " " + shadow.Offset2.Y;
            tbOrigin.Text = shadow.Origin.X + " " + shadow.Origin.Y;

            tbMatrix.Text = shadow.Matrix;

            pId.Visibility = pOn.Visibility = pType.Visibility = pObscured.Visibility = pColor.Visibility = pOpacity.Visibility =
                pOffset.Visibility = pColor2.Visibility = pOffset2.Visibility = pOrigin.Visibility = pMatrix.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VTextBox(VTextBox textBox)
        {
            tbId.Text = textBox.Id;
            tbStyle.Text = textBox.Style;

            pId.Visibility = pStyle.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VTextPath(VTextPath textPath)
        {
            tbId.Text = textPath.Id;
            tbOn.Text = textPath.On.ToString();
            tbStyle.Text = textPath.Style;
            tbFitShape.Text = textPath.FitShape.ToString();
            tbFitPath.Text = textPath.FitPath.ToString();
            tbTrim.Text = textPath.Trim.ToString();
            tbXScale.Text = textPath.XScale.ToString();
            tbString.Text = textPath.String;

            pId.Visibility = pOn.Visibility = pStyle.Visibility = pFitShape.Visibility = pFitPath.Visibility = pTrim.Visibility =
                pXScale.Visibility = pString.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VImageData(VImageData imageData)
        {
            tbId.Text = imageData.Id;
            tbSrc.Text = imageData.Src;
            tbCropBottom.Text = imageData.CropBottom.ToString();
            tbCropLeft.Text = imageData.CropLeft.ToString();
            tbCropRight.Text = imageData.CropRight.ToString();
            tbCropTop.Text = imageData.CropTop.ToString();
            tbGain.Text = imageData.Gain.ToString();
            tbBlackLevel.Text = imageData.BlackLevel.ToString();
            tbGamma.Text = imageData.Gamma.ToString();
            tbChromakey.Text = imageData.Chromakey;
            tbGrayScale.Text = imageData.GrayScale.ToString();
            tbBilevel.Text = imageData.Bilevel.ToString();

            pId.Visibility = pSrc.Visibility = pCropBottom.Visibility = pCropLeft.Visibility = pCropRight.Visibility = pCropTop.Visibility =
                pGain.Visibility = pBlackLevel.Visibility = pGamma.Visibility = pChromakey.Visibility = pGrayScale.Visibility = pBilevel.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VLine(VLine line)
        {
            tbId.Text = line.Id;
            tbStyle.Text = line.Style;
            tbHref.Text = line.Href;
            tbTarget.Text = line.Target;
            tbClass.Text = line.Class;
            tbTitle.Text = line.Title;
            tbAlt.Text = line.Alt;
            tbOpacity.Text = line.Opacity.ToString();
            tbChromakey.Text = line.Chromakey;
            tbStroke.Text = line.Stroke.ToString();
            tbStrokeColor.Text = line.StrokeColor;
            tbStrokeWeight.Text = line.StrokeWeight.ToString();
            tbPrint.Text = line.Print.ToString();
            tbCoordOrigin.Text = line.CoordOrigin.X + " " + line.CoordOrigin.Y;
            tbCoordSize.Text = line.CoordSize.X + " " + line.CoordSize.Y;
            tbWrapCoords.Text = line.WrapCoords;

            tbFrom.Text = line.From.X + " " + line.From.Y;
            tbTo.Text = line.To.X + " " + line.To.Y;

            pId.Visibility = pHref.Visibility = pFrom.Visibility = pTo.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VPolyLine(VPolyLine polyLine)
        {
            tbId.Text = polyLine.Id;
            tbStyle.Text = polyLine.Style;
            tbHref.Text = polyLine.Href;
            tbTarget.Text = polyLine.Target;
            tbClass.Text = polyLine.Class;
            tbTitle.Text = polyLine.Title;
            tbAlt.Text = polyLine.Alt;
            tbOpacity.Text = polyLine.Opacity.ToString();
            tbChromakey.Text = polyLine.Chromakey;
            tbStroke.Text = polyLine.Stroke.ToString();
            tbStrokeColor.Text = polyLine.StrokeColor;
            tbStrokeWeight.Text = polyLine.StrokeWeight.ToString();
            tbFill.Text = polyLine.Fill.ToString();
            tbFillColor.Text = polyLine.FillColor;
            tbPrint.Text = polyLine.Print.ToString();
            tbCoordOrigin.Text = polyLine.CoordOrigin.X + " " + polyLine.CoordOrigin.Y;
            tbCoordSize.Text = polyLine.CoordSize.X + " " + polyLine.CoordSize.Y;
            tbWrapCoords.Text = polyLine.WrapCoords;

            String str = "";

            for (int i = 0; i < polyLine.Points.Count(); i++)
            {
                str += polyLine.Points[i].X + " " + polyLine.Points[i].Y + " ";
            }

            tbPoints.Text = str.Trim();

            pId.Visibility = pHref.Visibility = pPoints.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility = pFill.Visibility = pFillColor.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VCurve(VCurve curve)
        {
            tbId.Text = curve.Id;
            tbStyle.Text = curve.Style;
            tbHref.Text = curve.Href;
            tbTarget.Text = curve.Target;
            tbClass.Text = curve.Class;
            tbTitle.Text = curve.Title;
            tbAlt.Text = curve.Alt;
            tbOpacity.Text = curve.Opacity.ToString();
            tbChromakey.Text = curve.Chromakey;
            tbStroke.Text = curve.Stroke.ToString();
            tbStrokeColor.Text = curve.StrokeColor;
            tbStrokeWeight.Text = curve.StrokeWeight.ToString();
            tbPrint.Text = curve.Print.ToString();
            tbCoordOrigin.Text = curve.CoordOrigin.X + " " + curve.CoordOrigin.Y;
            tbCoordSize.Text = curve.CoordSize.X + " " + curve.CoordSize.Y;
            tbWrapCoords.Text = curve.WrapCoords;

            tbFrom.Text = curve.From.X + " " + curve.From.Y;
            tbTo.Text = curve.To.X + " " + curve.To.Y;
            tbControl1.Text = curve.Control1.X + " " + curve.Control1.Y;
            tbControl2.Text = curve.Control2.X + " " + curve.Control2.Y;

            pId.Visibility = pHref.Visibility = pFrom.Visibility = pTo.Visibility = pControl1.Visibility = pControl2.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VRect(VRect rect)
        {
            tbId.Text = rect.Id;
            tbStyle.Text = rect.Style;
            tbHref.Text = rect.Href;
            tbTarget.Text = rect.Target;
            tbClass.Text = rect.Class;
            tbTitle.Text = rect.Title;
            tbAlt.Text = rect.Alt;
            tbOpacity.Text = rect.Opacity.ToString();
            tbChromakey.Text = rect.Chromakey;
            tbStroke.Text = rect.Stroke.ToString();
            tbStrokeColor.Text = rect.StrokeColor;
            tbStrokeWeight.Text = rect.StrokeWeight.ToString();
            tbPrint.Text = rect.Print.ToString();
            tbCoordOrigin.Text = rect.CoordOrigin.X + " " + rect.CoordOrigin.Y;
            tbCoordSize.Text = rect.CoordSize.X + " " + rect.CoordSize.Y;
            tbWrapCoords.Text = rect.WrapCoords;

            pId.Visibility = pHref.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VRoundRect(VRoundRect roundRect)
        {
            tbId.Text = roundRect.Id;
            tbStyle.Text = roundRect.Style;
            tbHref.Text = roundRect.Href;
            tbTarget.Text = roundRect.Target;
            tbClass.Text = roundRect.Class;
            tbTitle.Text = roundRect.Title;
            tbAlt.Text = roundRect.Alt;
            tbOpacity.Text = roundRect.Opacity.ToString();
            tbChromakey.Text = roundRect.Chromakey;
            tbStroke.Text = roundRect.Stroke.ToString();
            tbStrokeColor.Text = roundRect.StrokeColor;
            tbStrokeWeight.Text = roundRect.StrokeWeight.ToString();
            tbPrint.Text = roundRect.Print.ToString();
            tbCoordOrigin.Text = roundRect.CoordOrigin.X + " " + roundRect.CoordOrigin.Y;
            tbCoordSize.Text = roundRect.CoordSize.X + " " + roundRect.CoordSize.Y;
            tbWrapCoords.Text = roundRect.WrapCoords;

            tbArcSize.Text = roundRect.ArcSize.ToString();

            pId.Visibility = pHref.Visibility = pArcSize.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VOval(VOval oval)
        {
            tbId.Text = oval.Id;
            tbStyle.Text = oval.Style;
            tbHref.Text = oval.Href;
            tbTarget.Text = oval.Target;
            tbClass.Text = oval.Class;
            tbTitle.Text = oval.Title;
            tbAlt.Text = oval.Alt;
            tbOpacity.Text = oval.Opacity.ToString();
            tbChromakey.Text = oval.Chromakey;
            tbStroke.Text = oval.Stroke.ToString();
            tbStrokeColor.Text = oval.StrokeColor;
            tbStrokeWeight.Text = oval.StrokeWeight.ToString();
            tbPrint.Text = oval.Print.ToString();
            tbCoordOrigin.Text = oval.CoordOrigin.X + " " + oval.CoordOrigin.Y;
            tbCoordSize.Text = oval.CoordSize.X + " " + oval.CoordSize.Y;
            tbWrapCoords.Text = oval.WrapCoords;

            pId.Visibility = pHref.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VArc(VArc arc)
        {
            tbId.Text = arc.Id;
            tbStyle.Text = arc.Style;
            tbHref.Text = arc.Href;
            tbTarget.Text = arc.Target;
            tbClass.Text = arc.Class;
            tbTitle.Text = arc.Title;
            tbAlt.Text = arc.Alt;
            tbOpacity.Text = arc.Opacity.ToString();
            tbChromakey.Text = arc.Chromakey;
            tbStroke.Text = arc.Stroke.ToString();
            tbStrokeColor.Text = arc.StrokeColor;
            tbStrokeWeight.Text = arc.StrokeWeight.ToString();
            tbPrint.Text = arc.Print.ToString();
            tbCoordOrigin.Text = arc.CoordOrigin.X + " " + arc.CoordOrigin.Y;
            tbCoordSize.Text = arc.CoordSize.X + " " + arc.CoordSize.Y;
            tbWrapCoords.Text = arc.WrapCoords;

            tbStartAngle.Text = arc.StartAngle.ToString();
            tbEndAngle.Text = arc.EndAngle.ToString();

            pId.Visibility = pHref.Visibility = pStartAngle.Visibility = pEndAngle.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        private void ShowProperty_VImage(VImage image)
        {
            tbId.Text = image.Id;
            tbStyle.Text = image.Style;
            tbHref.Text = image.Href;
            tbTarget.Text = image.Target;
            tbClass.Text = image.Class;
            tbTitle.Text = image.Title;
            tbAlt.Text = image.Alt;
            tbOpacity.Text = image.Opacity.ToString();
            tbChromakey.Text = image.Chromakey;
            tbStroke.Text = image.Stroke.ToString();
            tbStrokeColor.Text = image.StrokeColor;
            tbStrokeWeight.Text = image.StrokeWeight.ToString();
            tbPrint.Text = image.Print.ToString();
            tbCoordOrigin.Text = image.CoordOrigin.X + " " + image.CoordOrigin.Y;
            tbCoordSize.Text = image.CoordSize.X + " " + image.CoordSize.Y;
            tbWrapCoords.Text = image.WrapCoords;

            tbSrc.Text = image.Src;
            tbCropBottom.Text = image.CropBottom.ToString();
            tbCropLeft.Text = image.CropLeft.ToString();
            tbCropRight.Text = image.CropRight.ToString();
            tbCropTop.Text = image.CropTop.ToString();
            tbEmbossColor.Text = image.EmbossColor;
            tbGain.Text = image.Gain.ToString();
            tbBlackLevel.Text = image.BlackLevel.ToString();
            tbGamma.Text = image.Gamma.ToString();
            tbGrayScale.Text = image.GrayScale.ToString();
            tbBilevel.Text = image.Bilevel.ToString();

            pId.Visibility = pHref.Visibility = pSrc.Visibility = pCropBottom.Visibility =
                pCropLeft.Visibility = pCropRight.Visibility = pCropTop.Visibility =
                pTarget.Visibility = pClass.Visibility = pTitle.Visibility = pAlt.Visibility = pStyle.Visibility =
                pOpacity.Visibility = pChromakey.Visibility = pStroke.Visibility = pStrokeColor.Visibility =
                pStrokeWeight.Visibility = pEmbossColor.Visibility = pGain.Visibility =
                pBlackLevel.Visibility = pGamma.Visibility = pGrayScale.Visibility = pBilevel.Visibility =
                pPrint.Visibility = pCoordOrigin.Visibility = pCoordSize.Visibility = pWrapCoords.Visibility = Visibility.Visible;
        }

        #endregion

        #region Import/Export

        private void btnMoFile_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
            //ofd.DefaultExt = ".vml";
            //ofd.Filter = "VML file|*.vml";

            if (ofd.ShowDialog() == true)
            {
                String fileName = ofd.FileName;

                root = FileManager.ReadFile(fileName);
                RefreshOutline();
            }
        }

        private void btnLuuFile_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
            sfd.DefaultExt = ".vml";
            sfd.Filter = "VML files|*.vml";

            if (sfd.ShowDialog() == true)
            {
                String fileName = sfd.FileName;


            }
        }

        private void RefreshOutline()
        {
            TreeView.Items.Clear();

            AddOutline(null, null, null);
        }

        //modify
        private void AddOutline(VGroup group, String index, TreeViewItem node)
        {
            if (root == null)
                return;

            if (group == null)
            {
                for (int i = 0; i < root.Count(); i++)
                {
                    //Shape
                    if (root[i] is VShape)
                    {
                        VShape obj = root[i] as VShape;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "Shape";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "Shape";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "Shape");
                        }
                    }
                    //ShapeType
                    else if (root[i] is VShapeType)
                    {
                        VShapeType obj = root[i] as VShapeType;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "ShapeType";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "ShapeType";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "ShapeType");
                        }
                    }
                    //Line
                    else if (root[i] is VLine)
                    {
                        VLine obj = root[i] as VLine;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "Line";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "Line";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "Line");
                        }
                    }
                    //PolyLine
                    else if (root[i] is VPolyLine)
                    {
                        VPolyLine obj = root[i] as VPolyLine;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "PolyLine";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "PolyLine";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "PolyLine");
                        }
                    }
                    //Curve
                    else if (root[i] is VCurve)
                    {
                        VCurve obj = root[i] as VCurve;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "Curve";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "Curve";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "Curve");
                        }
                    }
                    //Rect
                    else if (root[i] is VRect)
                    {
                        VRect obj = root[i] as VRect;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "Rect";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "Rect";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "Rect");
                        }
                    }
                    //RoundRect
                    else if (root[i] is VRoundRect)
                    {
                        VRoundRect obj = root[i] as VRoundRect;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "RoundRect";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "RoundRect";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "RoundRect");
                        }
                    }
                    //Oval
                    else if (root[i] is VOval)
                    {
                        VOval obj = root[i] as VOval;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "Oval";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "Oval";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "Oval");
                        }
                    }
                    //Arc
                    else if (root[i] is VArc)
                    {
                        VArc obj = root[i] as VArc;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "Arc";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "Arc";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "Arc");
                        }
                    }
                    //Image
                    else if (root[i] is VImage)
                    {
                        VImage obj = root[i] as VImage;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "Image";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add((i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add((i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add((i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "Image";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "Image");
                        }
                    }
                    //Group
                    else if (root[i] is VGroup)
                    {
                        VGroup obj = root[i] as VGroup;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = (i + 1) + " " + "Group";

                            AddOutline(obj, (i + 1).ToString(), item);

                            TreeView.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = (i + 1) + " " + "Group";
                            TreeView.Items.Add(mItem);
                            //TreeView.Items.Add((i + 1) + " " + "Group");
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < group.Elements.Count(); i++)
                {
                    //Shape
                    if (group.Elements[i] is VShape)
                    {
                        VShape obj = group.Elements[i] as VShape;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "Shape";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {

                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "Shape";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "Shape");
                        }
                    }
                    //ShapeType
                    else if (group.Elements[i] is VShapeType)
                    {
                        VShapeType obj = group.Elements[i] as VShapeType;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "ShapeType";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "ShapeType";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "ShapeType");
                        }
                    }
                    //Line
                    else if (group.Elements[i] is VLine)
                    {
                        VLine obj = group.Elements[i] as VLine;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "Line";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "Line";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "Line");
                        }
                    }
                    //PolyLine
                    else if (group.Elements[i] is VPolyLine)
                    {
                        VPolyLine obj = group.Elements[i] as VPolyLine;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "PolyLine";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "PolyLine";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "PolyLine");
                        }
                    }
                    //Curve
                    else if (group.Elements[i] is VCurve)
                    {
                        VCurve obj = group.Elements[i] as VCurve;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "Curve";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "Curve";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "Curve");
                        }
                    }
                    //Rect
                    else if (group.Elements[i] is VRect)
                    {
                        VRect obj = group.Elements[i] as VRect;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "Rect";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "Rect";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "Rect");
                        }
                    }
                    //RoundRect
                    else if (group.Elements[i] is VRoundRect)
                    {
                        VRoundRect obj = group.Elements[i] as VRoundRect;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "RoundRect";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "RoundRect";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "RoundRect");
                        }
                    }
                    //Oval
                    else if (group.Elements[i] is VOval)
                    {
                        VOval obj = group.Elements[i] as VOval;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "Oval";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "Oval";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "Oval");
                        }
                    }
                    //Arc
                    else if (group.Elements[i] is VArc)
                    {
                        VArc obj = group.Elements[i] as VArc;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "Arc";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");;
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "Arc";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "Arc");
                        }
                    }
                    //Image
                    else if (group.Elements[i] is VImage)
                    {
                        VImage obj = group.Elements[i] as VImage;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "Image";

                            for (int j = 0; j < obj.Elements.Count(); j++)
                            {
                                //Path
                                if (obj.Elements[j] is VPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Path";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Path");
                                }
                                //Formulars
                                else if (obj.Elements[j] is VFormulas)
                                {
                                    VFormulas formulas = obj.Elements[j] as VFormulas;

                                    if (formulas.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";

                                        for (int k = 0; k < formulas.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " F");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Formulas");
                                    }

                                }
                                //Handles
                                else if (obj.Elements[j] is VHandles)
                                {
                                    VHandles handles = obj.Elements[j] as VHandles;

                                    if (handles.Elements.Count() > 0)
                                    {
                                        TreeViewItem item2 = new TreeViewItem();
                                        item2.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";

                                        for (int k = 0; k < handles.Elements.Count(); k++)
                                        {
                                            TreeViewItem mItem = new TreeViewItem();
                                            mItem.Header = index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H";
                                            item2.Items.Add(mItem);
                                            //item2.Items.Add(index + "." + (i + 1) + "." + (j + 1) + "." + (k + 1) + " H");
                                        }

                                        item.Items.Add(item2);
                                    }
                                    else
                                    {
                                        TreeViewItem mItem = new TreeViewItem();
                                        mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " " + "Handles";
                                        item.Items.Add(mItem);
                                        //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " " + "Handles");
                                    }
                                }
                                //Fill
                                else if (obj.Elements[j] is VFill)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Fill";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Fill");
                                }
                                //Stroke
                                else if (obj.Elements[j] is VStroke)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Stroke";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Stroke");
                                }
                                //Shadow
                                else if (obj.Elements[j] is VShadow)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " Shadow";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " Shadow");
                                }
                                //TextBox
                                else if (obj.Elements[j] is VTextBox)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextBox";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextBox");
                                }
                                //TextPath
                                else if (obj.Elements[j] is VTextPath)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " TextPath";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " TextPath");
                                }
                                //ImageData
                                else if (obj.Elements[j] is VImageData)
                                {
                                    TreeViewItem mItem = new TreeViewItem();
                                    mItem.Header = index + "." + (i + 1) + "." + (j + 1) + " ImageData";
                                    item.Items.Add(mItem);
                                    //item.Items.Add(index + "." + (i + 1) + "." + (j + 1) + " ImageData");
                                }
                            }

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "Image";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "Image");
                        }
                    }
                    //Group
                    else if (group.Elements[i] is VGroup)
                    {
                        VGroup obj = group.Elements[i] as VGroup;

                        if (obj.Elements.Count() > 0)
                        {
                            TreeViewItem item = new TreeViewItem();
                            item.Header = index + "." + (i + 1) + " " + "Group";

                            AddOutline(obj, index + "." + (i + 1).ToString(), item);

                            node.Items.Add(item);
                        }
                        else
                        {
                            TreeViewItem mItem = new TreeViewItem();
                            mItem.Header = index + "." + (i + 1) + " " + "Group";
                            node.Items.Add(mItem);
                            //node.Items.Add(index + "." + (i + 1) + " " + "Group");
                        }
                    }
                }
            }
        }
        //modify
        private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            if (TreeView.SelectedItem != null)
            {
                String str = "";

                if (TreeView.SelectedItem is TreeViewItem)
                {
                    TreeViewItem item = TreeView.SelectedItem as TreeViewItem;
                    str = item.Header as String;
                }
                else
                {
                    str = TreeView.SelectedItem as String;
                }

                string[] strArr = str.Split(' ');

                string[] numArr = strArr[0].Split('.');

                Parent = null;
                parentGroup = null;
                pos = int.Parse(numArr[numArr.Length - 1]) - 1;
                pathPos = numArr;


                for (int i = 0; i < numArr.Length; i++)
                {

                    if (Parent == null)
                    {
                        Parent = root[int.Parse(numArr[i]) - 1];
                    }
                    else
                    {
                        if (Parent is VGroup)
                        {
                            parentGroup = Parent as VGroup;
                            Parent = (Parent as VGroup).Elements[int.Parse(numArr[i]) - 1];
                        }
                        else if (Parent is VShapeBase)
                        {
                            Parent = (Parent as VShapeBase).Elements[int.Parse(numArr[i]) - 1];
                        }
                        else if (Parent is VHandles)
                        {
                            Parent = (Parent as VHandles).Elements[int.Parse(numArr[i]) - 1];
                        }
                        else if (Parent is VFormulas)
                        {
                            Parent = (Parent as VFormulas).Elements[int.Parse(numArr[i]) - 1];
                        }
                    }
                }

                numError = 0;
                ShowProperty(Parent);
                RefreshError();
            }
            else
            {
                HideAllProperties();
                numError = 0;
                RefreshError();
            }

            if (TreeView.SelectedItem != null)
            {
                if (Parent is VGroup)
                {
                    btnAddShape.Visibility = Visibility.Visible;
                    btnAddShapeType.Visibility = Visibility.Visible;
                    btnAddCurve.Visibility = Visibility.Visible;
                    btnAddLine.Visibility = Visibility.Visible;
                    btnAddPolyLine.Visibility = Visibility.Visible;
                    btnAddArc.Visibility = Visibility.Visible;
                    btnAddRect.Visibility = Visibility.Visible;
                    btnAddRoundRect.Visibility = Visibility.Visible;
                    btnAddOval.Visibility = Visibility.Visible;
                    btnAddImage.Visibility = Visibility.Visible;
                    btnAddGroup.Visibility = Visibility.Visible;
                }
                else
                {
                    btnAddShape.Visibility = Visibility.Collapsed;
                    btnAddShapeType.Visibility = Visibility.Collapsed;
                    btnAddLine.Visibility = Visibility.Collapsed;
                    btnAddPolyLine.Visibility = Visibility.Collapsed;
                    btnAddCurve.Visibility = Visibility.Collapsed;
                    btnAddArc.Visibility = Visibility.Collapsed;
                    btnAddOval.Visibility = Visibility.Collapsed;
                    btnAddRect.Visibility = Visibility.Collapsed;
                    btnAddRoundRect.Visibility = Visibility.Collapsed;
                    btnAddImage.Visibility = Visibility.Collapsed;
                    btnAddGroup.Visibility = Visibility.Collapsed;
                }

                if (Parent is VShape || Parent is VShapeType || Parent is VLine || Parent is VPolyLine || Parent is VCurve ||
                    Parent is VArc || Parent is VOval || Parent is VRect || Parent is VRoundRect || Parent is VImage)
                {
                    btnAddPath.Visibility = Visibility.Visible;
                    btnAddFormulas.Visibility = Visibility.Visible;
                    btnAddHandles.Visibility = Visibility.Visible;
                    btnAddFill.Visibility = Visibility.Visible;
                    btnAddStroke.Visibility = Visibility.Visible;
                    btnAddShadow.Visibility = Visibility.Visible;
                    btnAddTextBox.Visibility = Visibility.Visible;
                    btnAddTextPath.Visibility = Visibility.Visible;
                    btnAddImageData.Visibility = Visibility.Visible;
                }
                else
                {
                    btnAddPath.Visibility = Visibility.Collapsed;
                    btnAddFormulas.Visibility = Visibility.Collapsed;
                    btnAddHandles.Visibility = Visibility.Collapsed;
                    btnAddFill.Visibility = Visibility.Collapsed;
                    btnAddStroke.Visibility = Visibility.Collapsed;
                    btnAddShadow.Visibility = Visibility.Collapsed;
                    btnAddTextBox.Visibility = Visibility.Collapsed;
                    btnAddTextPath.Visibility = Visibility.Collapsed;
                    btnAddImageData.Visibility = Visibility.Collapsed;
                }

                if (Parent is VHandles)
                {
                    btnAddH.Visibility = Visibility.Visible;
                }
                else
                {
                    btnAddH.Visibility = Visibility.Collapsed;
                }

                if (Parent is VFormulas)
                {
                    btnAddF.Visibility = Visibility.Visible;
                }
                else
                {
                    btnAddF.Visibility = Visibility.Collapsed;
                }

                if ((Parent is VShapeElement && !(Parent is VHandles) && !(Parent is VFormulas)) || Parent is VH || Parent is VF)
                {
                    mnNoThing.Visibility = Visibility.Visible;
                }
                else
                {
                    mnNoThing.Visibility = Visibility.Collapsed;
                }
            }
            else
            {
                btnAddShape.Visibility = Visibility.Visible;
                btnAddShapeType.Visibility = Visibility.Visible;
                btnAddLine.Visibility = Visibility.Visible;
                btnAddPolyLine.Visibility = Visibility.Visible;
                btnAddCurve.Visibility = Visibility.Visible;
                btnAddArc.Visibility = Visibility.Visible;
                btnAddOval.Visibility = Visibility.Visible;
                btnAddRoundRect.Visibility = Visibility.Visible;
                btnAddRect.Visibility = Visibility.Visible;
                btnAddImage.Visibility = Visibility.Visible;
                btnAddGroup.Visibility = Visibility.Visible;
                btnAddPath.Visibility = Visibility.Collapsed;
                btnAddFormulas.Visibility = Visibility.Collapsed;
                btnAddHandles.Visibility = Visibility.Collapsed;
                btnAddFill.Visibility = Visibility.Collapsed;
                btnAddStroke.Visibility = Visibility.Collapsed;
                btnAddShadow.Visibility = Visibility.Collapsed;
                btnAddTextBox.Visibility = Visibility.Collapsed;
                btnAddTextPath.Visibility = Visibility.Collapsed;
                btnAddImageData.Visibility = Visibility.Collapsed;
                btnAddF.Visibility = Visibility.Collapsed;
                btnAddH.Visibility = Visibility.Collapsed;
                mnNoThing.Visibility = Visibility.Collapsed;
            }
        }

        #endregion

        #region Propertiy Changed Events

        private void RefreshError()
        {
            if (numError == 0)
            {
                pNotification.Visibility = Visibility.Collapsed;
            }
            else
            {
                pNotification.Visibility = Visibility.Visible;
            }
        }

        private void FocusDisplay(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                TreeView.Focus();
            }
        }

        //  ID
        private bool CheckId(VGroup obj, string id)
        {
            if (root == null)
                return false;

            if (obj == null)
            {
                foreach (VObject vobj in root)
                {
                    if (vobj is VBackground)
                    {
                        if ((vobj as VBackground).Id == id && Parent != vobj)
                        {
                            return false;
                        }
                    }
                    else if (vobj is VShapeBase)
                    {
                        if ((vobj as VShapeBase).Id == id && Parent != vobj)
                        {
                            return false;
                        }

                        foreach (VShapeElement sb in (vobj as VShapeBase).Elements)
                        {
                            if (sb is VPath)
                            {
                                if ((sb as VPath).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VFill)
                            {
                                if ((sb as VFill).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VStroke)
                            {
                                if ((sb as VStroke).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VShadow)
                            {
                                if ((sb as VShadow).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VTextBox)
                            {
                                if ((sb as VTextBox).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VTextPath)
                            {
                                if ((sb as VTextPath).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VImageData)
                            {
                                if ((sb as VImageData).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                        }
                    }
                    else if (vobj is VGroup)
                    {
                        if ((vobj as VGroup).Id == id && Parent != vobj)
                        {
                            return false;
                        }

                        foreach (VGroupElement ge in (vobj as VGroup).Elements)
                        {
                            return CheckId(vobj as VGroup, id);
                        }
                    }
                }

                return true;
            }
            else
            {
                foreach (VObject vobj in obj.Elements)
                {
                    if (vobj is VBackground)
                    {
                        if ((vobj as VBackground).Id == id && Parent != vobj)
                        {
                            return false;
                        }
                    }
                    else if (vobj is VShapeBase)
                    {
                        if ((vobj as VShapeBase).Id == id && Parent != vobj)
                        {
                            return false;
                        }

                        foreach (VShapeElement sb in (vobj as VShapeBase).Elements)
                        {
                            if (sb is VPath)
                            {
                                if ((sb as VPath).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VFill)
                            {
                                if ((sb as VFill).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VStroke)
                            {
                                if ((sb as VStroke).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VShadow)
                            {
                                if ((sb as VShadow).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VTextBox)
                            {
                                if ((sb as VTextBox).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VTextPath)
                            {
                                if ((sb as VTextPath).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                            else if (sb is VImageData)
                            {
                                if ((sb as VImageData).Id == id && Parent != sb)
                                {
                                    return false;
                                }
                            }
                        }
                    }
                    else if (vobj is VGroup)
                    {
                        if ((vobj as VGroup).Id == id && Parent != vobj)
                        {
                            return false;
                        }

                        foreach (VGroupElement ge in (vobj as VGroup).Elements)
                        {
                            return CheckId(vobj as VGroup, id);
                        }
                    }
                }

                return true;
            }
        }

        private void pId_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pId.Visibility == Visibility.Visible)
            {
                if (!CheckId(null, tbId.Text.Trim()))
                {
                    tbId.Background = ErrorBrush;
                    numError++;

                }
                else
                {
                    tbId.Background = TrueBrush;
                }
            }
        }

        private void tbId_LostFocus(object sender, RoutedEventArgs e)
        {
            string id = tbId.Text.Trim();

            if (!CheckId(null, tbId.Text.Trim()))
            {
                if (((SolidColorBrush)tbId.Background).Color == TrueColor)
                {
                    tbId.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if (((SolidColorBrush)tbId.Background).Color == ErrorColor)
                {
                    tbId.Background = TrueBrush;
                    numError--;
                }

                if (id == "")
                {
                    if (Parent is VBackground)
                    {
                        (Parent as VBackground).Id = null;
                    }
                    else if (Parent is VShapeBase)
                    {
                        (Parent as VShapeBase).Id = null;
                    }
                    else if (Parent is VGroup)
                    {
                        (Parent as VGroup).Id = null;
                    }
                    else if (Parent is VPath)
                    {
                        (Parent as VPath).Id = null;
                    }
                    else if (Parent is VFill)
                    {
                        (Parent as VFill).Id = null;
                    }
                    else if (Parent is VStroke)
                    {
                        (Parent as VStroke).Id = null;
                    }
                    else if (Parent is VShadow)
                    {
                        (Parent as VShadow).Id = null;
                    }
                    else if (Parent is VTextBox)
                    {
                        (Parent as VTextBox).Id = null;
                    }
                    else if (Parent is VTextPath)
                    {
                        (Parent as VTextPath).Id = null;
                    }
                    else if (Parent is VImageData)
                    {
                        (Parent as VImageData).Id = null;
                    }
                }
                else
                {
                    if (Parent is VBackground)
                    {
                        (Parent as VBackground).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VShapeBase)
                    {
                        (Parent as VShapeBase).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VGroup)
                    {
                        (Parent as VGroup).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VPath)
                    {
                        (Parent as VPath).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VFill)
                    {
                        (Parent as VFill).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VStroke)
                    {
                        (Parent as VStroke).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VShadow)
                    {
                        (Parent as VShadow).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VTextBox)
                    {
                        (Parent as VTextBox).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VTextPath)
                    {
                        (Parent as VTextPath).Id = tbId.Text.Trim();
                    }
                    else if (Parent is VImageData)
                    {
                        (Parent as VImageData).Id = tbId.Text.Trim();
                    }
                }
            }

            RefreshError();
        }

        //  Type
        private bool CheckType(VGroup group, string type)
        {
            if (Parent is VFill)
            {
                if (type == "")
                {
                    tbType.Text = "solid";
                    return true;
                }

                string[] t = { "solid", "gradient", "gradientradial", "tile", "pattern", "frame" };

                foreach (var obj in t)
                {
                    if (type.ToLower() == obj)
                        return true;
                }

                return false;
            }
            else if (Parent is VShadow)
            {
                if (type == "")
                {
                    tbType.Text = "single";
                    return true;
                }

                string[] t = { "single", "double", "emboss", "perspective" };

                foreach (var obj in t)
                {
                    if (type.ToLower() == obj)
                        return true;
                }

                return false;
            }

            if (type.Trim() == "")
                return true;

            if (group == null)
            {
                foreach (VObject obj in root)
                {
                    if (obj is VShapeType)
                    {
                        if ("#" + (obj as VShapeType).Id == type && Parent != obj)
                        {
                            return true;
                        }
                    }
                    else if (obj is VGroup)
                    {
                        if (CheckType(obj as VGroup, type))
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
            else
            {
                foreach (VObject obj in group.Elements)
                {
                    if (obj is VShapeType)
                    {
                        if ("#" + (obj as VShapeType).Id == type && Parent != obj)
                        {
                            return true;
                        }
                    }
                    else if (obj is VGroup)
                    {
                        if (CheckType(obj as VGroup, type))
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
        }

        private void pType_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pType.Visibility == Visibility.Visible)
            {
                if (Parent is VShape)
                {
                    tbType.ToolTip = "ID of a ShapeType";
                }
                else if (Parent is VFill)
                {
                    tbType.ToolTip = "Solid | Gradient | Gradientradial | Tile | Pattern | Frame";
                }
                else if (Parent is VShadow)
                {
                    tbType.ToolTip = "Single | Double | Emboss | Perspective";
                }

                if (!CheckType(null, tbType.Text.Trim()))
                {
                    tbType.Background = ErrorBrush;
                    numError++;

                }
                else
                {
                    tbType.Background = TrueBrush;
                }
            }
        }

        private void tbType_LostFocus(object sender, RoutedEventArgs e)
        {
            string type = tbType.Text.Trim();

            if (!CheckType(null, tbType.Text.Trim()))
            {
                if ((tbType.Background as SolidColorBrush).Color == TrueColor)
                {
                    tbType.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tbType.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbType.Background = TrueBrush;
                    numError--;
                }

                if (type == "")
                {
                    if (Parent is VShape)
                    {
                        (Parent as VShape).Type = null;
                    }
                    else if (Parent is VShadow)
                    {
                        (Parent as VShadow).Type = null;
                    }
                    else if (Parent is VFill)
                    {
                        (Parent as VFill).Type = null;
                    }
                }
                else
                {
                    if (Parent is VShape)
                    {
                        (Parent as VShape).Type = type;
                    }
                    else if (Parent is VShadow)
                    {
                        (Parent as VShadow).Type = type;
                    }
                    else if (Parent is VFill)
                    {
                        (Parent as VFill).Type = type;
                    }
                }
            }

            RefreshError();
        }

        //  Adj
        private void tbAdj_LostFocus(object sender, RoutedEventArgs e)
        {
            string adj = tbAdj.Text.Trim();

            if (Parent is VShape)
            {
                if ((Parent as VShape).Adj == adj || ((Parent as VShape).Adj == null && adj == ""))
                {
                    return;
                }
            }
            else if (Parent is VShapeType)
            {
                if ((Parent as VShapeType).Adj == adj || ((Parent as VShapeType).Adj == null && adj == ""))
                {
                    return;
                }
            }

            if (adj == "")
            {
                if (Parent is VShape)
                {
                    (Parent as VShape).Adj = null;
                }
                else if (Parent is VShapeType)
                {
                    (Parent as VShapeType).Adj = null;
                }
            }
            else
            {
                if (Parent is VShape)
                {
                    (Parent as VShape).Adj = adj;
                }
                else if (Parent is VShapeType)
                {
                    (Parent as VShapeType).Adj = adj;
                }
            }
        }

        //  Path
        private void tbPath_LostFocus(object sender, RoutedEventArgs e)
        {
            string path = tbPath.Text.Trim();

            if (Parent is VShape)
            {
                if ((Parent as VShape).Path == path || ((Parent as VShape).Path == null && path == ""))
                {
                    return;
                }
            }
            else if (Parent is VShapeType)
            {
                if ((Parent as VShapeType).Path == path || ((Parent as VShapeType).Path == null && path == ""))
                {
                    return;
                }
            }

            if (path == "")
            {
                if (Parent is VShape)
                {
                    (Parent as VShape).Path = null;
                }
                else if (Parent is VShapeType)
                {
                    (Parent as VShapeType).Path = null;
                }
            }
            else
            {
                if (Parent is VShape)
                {
                    (Parent as VShape).Path = path;
                }
                else if (Parent is VShapeType)
                {
                    (Parent as VShapeType).Path = path;
                }
            }
        }

        //  Href
        private void tbHref_LostFocus(object sender, RoutedEventArgs e)
        {
            string href = tbHref.Text.Trim();

            if (Parent is VGroupElement)
            {
                if ((Parent as VGroupElement).Href == href || ((Parent as VGroupElement).Href == null && href == ""))
                {
                    return;
                }
            }

            if (href == "")
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Href = null;
                }
            }
            else
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Href = href;
                }
            }
        }

        //  Target
        private void tbTarget_LostFocus(object sender, RoutedEventArgs e)
        {
            string target = tbTarget.Text.Trim();

            if (Parent is VGroupElement)
            {
                if ((Parent as VGroupElement).Target == target || ((Parent as VGroupElement).Target == null && target == ""))
                {
                    return;
                }
            }

            if (target == "")
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Target = null;
                }
            }
            else
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Target = target;
                }
            }
        }

        //  Class
        private void tbClass_LostFocus(object sender, RoutedEventArgs e)
        {
            string cl = tbClass.Text.Trim();

            if (Parent is VGroupElement)
            {
                if ((Parent as VGroupElement).Class == cl || ((Parent as VGroupElement).Class == null && cl == ""))
                {
                    return;
                }
            }

            if (cl == "")
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Class = null;
                }
            }
            else
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Class = cl;
                }
            }
        }

        //  Title
        private void tbTitle_LostFocus(object sender, RoutedEventArgs e)
        {
            string title = tbTitle.Text.Trim();

            if (Parent is VGroupElement)
            {
                if ((Parent as VGroupElement).Title == title || ((Parent as VGroupElement).Title == null && title == ""))
                {
                    return;
                }
            }

            if (title == "")
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Title = null;
                }
            }
            else
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Title = title;
                }
            }
        }

        //  Alt
        private void tbAlt_LostFocus(object sender, RoutedEventArgs e)
        {
            string alt = tbAlt.Text.Trim();

            if (Parent is VGroupElement)
            {
                if ((Parent as VGroupElement).Alt == alt || ((Parent as VGroupElement).Alt == null && alt == ""))
                {
                    return;
                }
            }

            if (alt == "")
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Alt = null;
                }
            }
            else
            {
                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).Alt = alt;
                }
            }
        }

        //  Opacity
        private void tbOpacity_TextChanged(object sender, TextChangedEventArgs e)
        {
            string result = "";
            bool checkDot = true;

            foreach (var c in tbOpacity.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '.' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
            }

            tbOpacity.Text = result.ToString();
            tbOpacity.CaretIndex = result.Length;
        }

        private void pOpacity_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pOpacity.Visibility == Visibility.Visible)
            {
                try
                {
                    float o = float.Parse(tbOpacity.Text);

                    if (o < 0f || o > 1f)
                    {
                        tbOpacity.Background = ErrorBrush;
                        numError++;
                    }
                    else
                    {
                        tbOpacity.Background = TrueBrush;
                    }
                }
                catch
                {
                    tbOpacity.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbOpacity_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                float opacity = float.Parse(tbOpacity.Text);

                if (opacity > 1f || opacity < 0f)
                {
                    if ((tbOpacity.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbOpacity.Background = ErrorBrush;
                        numError++;
                    }
                }
                else
                {
                    if ((tbOpacity.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbOpacity.Background = TrueBrush;
                        numError--;
                    }

                    if (Parent is VShapeBase)
                    {
                        (Parent as VShapeBase).Opacity = opacity;
                    }
                    else if (Parent is VFill)
                    {
                        (Parent as VFill).Opacity = opacity;
                    }
                    else if (Parent is VShadow)
                    {
                        (Parent as VShadow).Opacity = opacity;
                    }
                    else if (Parent is VStroke)
                    {
                        (Parent as VStroke).Opacity = opacity;
                    }
                }
            }
            catch
            {
                if ((tbOpacity.Background as SolidColorBrush).Color == TrueColor)
                {
                    tbOpacity.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  Chromakey
        private void tbChromakey_LostFocus(object sender, RoutedEventArgs e)
        {
            string chromakey = tbChromakey.Text.Trim().ToLower();

            if (Parent is VShapeBase)
            {
                if ((Parent as VShapeBase).Chromakey == chromakey || ((Parent as VShapeBase).Chromakey == null && chromakey == ""))
                {
                    return;
                }
            }
            else if (Parent is VImageData)
            {
                if ((Parent as VImageData).Chromakey.ToLower() == chromakey || ((Parent as VImageData).Chromakey == null && chromakey == ""))
                {
                    return;
                }
            }


            if (chromakey == "")
            {
                if (Parent is VShapeBase)
                {
                    (Parent as VShapeBase).Chromakey = null;
                }
                else if (Parent is VImageData)
                {
                    (Parent as VImageData).Chromakey = null;
                }
            }
            else
            {
                if (Parent is VShapeBase)
                {
                    (Parent as VShapeBase).Chromakey = chromakey;
                }
                else if (Parent is VImageData)
                {
                    (Parent as VImageData).Chromakey = chromakey;
                }
            }
        }

        //  Stroke
        private void tbStroke_LostFocus(object sender, RoutedEventArgs e)
        {
            string stroke = tbStroke.Text.Trim().ToLower();

            if (Parent is VShapeBase)
            {
                if (stroke == "")
                {
                    tbStroke.Text = "True";
                    (Parent as VShapeBase).Stroke = true;

                    if ((tbStroke.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbStroke.Background = TrueBrush;
                        numError--;
                    }
                }
                else
                {
                    try
                    {
                        (Parent as VShapeBase).Stroke = bool.Parse(stroke);

                        if ((tbStroke.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tbStroke.Background = TrueBrush;
                            numError--;
                        }
                    }
                    catch
                    {
                        if ((tbStroke.Background as SolidColorBrush).Color == TrueColor)
                        {
                            tbStroke.Background = ErrorBrush;
                            numError++;
                        }
                    }
                }

                RefreshError();
            }
        }

        private void pStroke_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pStroke.Visibility == Visibility.Visible)
            {
                string stroke = tbStroke.Text.Trim().ToLower();

                if (stroke == "false" || stroke == "true")
                {
                    tbStroke.Background = TrueBrush;
                }
                else
                {
                    tbStroke.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        //  StrokeColor
        private void tbStrokeColor_LostFocus(object sender, RoutedEventArgs e)
        {
            string strokeColor = tbStrokeColor.Text.Trim().ToLower();

            if (Parent is VShapeBase)
            {
                if ((Parent as VShapeBase).StrokeColor == strokeColor || ((Parent as VShapeBase).StrokeColor == null && strokeColor == ""))
                {
                    return;
                }

                if (strokeColor == "")
                {
                    (Parent as VShapeBase).StrokeColor = null;
                }
                else
                {
                    (Parent as VShapeBase).StrokeColor = strokeColor;
                }
            }
        }

        //  StrokeWeight
        private void tbStrokeWeight_TextChanged(object sender, TextChangedEventArgs e)
        {
            string result = "";
            bool checkDot = true;

            foreach (var c in tbStrokeWeight.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '.' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
            }

            tbStrokeWeight.Text = result.ToString();
            tbStrokeWeight.CaretIndex = result.Length;
        }

        private void tbStrokeWeight_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VShapeBase)
            {
                try
                {
                    float weight = float.Parse(tbStrokeWeight.Text);

                    if ((tbStrokeWeight.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbStrokeWeight.Background = TrueBrush;
                        numError--;
                    }

                    (Parent as VShapeBase).StrokeWeight = weight;
                }
                catch
                {
                    if (tbStrokeWeight.Text.Trim() == "")
                    {
                        if ((tbStrokeWeight.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tbStrokeWeight.Background = TrueBrush;
                            numError--;
                        }

                        tbStrokeWeight.Text = "0.75";
                        (Parent as VShapeBase).StrokeWeight = 0.75f;
                    }
                    else if ((tbStrokeWeight.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbStrokeWeight.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        private void pStrokeWeight_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pStrokeWeight.Visibility == Visibility.Visible)
            {
                try
                {
                    float weight = float.Parse(tbStrokeWeight.Text);

                    tbStrokeWeight.Background = TrueBrush;
                }
                catch
                {
                    tbStrokeWeight.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        //  Fill
        private void pFill_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFill.Visibility == Visibility.Visible)
            {
                string fill = tbFill.Text.Trim().ToLower();

                if (fill == "false" || fill == "true")
                {
                    tbFill.Background = TrueBrush;
                }
                else
                {
                    tbFill.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbFill_LostFocus(object sender, RoutedEventArgs e)
        {
            string fill = tbFill.Text.Trim().ToLower();

            if (fill == "")
            {
                tbFill.Text = "True";

                if (Parent is VShapeBase)
                {
                    (Parent as VShapeBase).Fill = true;
                }
                else if (Parent is VBackground)
                {
                    (Parent as VBackground).Fill = true;
                }

                if ((tbFill.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbFill.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VShapeBase)
                    {
                        (Parent as VShapeBase).Fill = bool.Parse(fill);
                    }
                    else if (Parent is VBackground)
                    {
                        (Parent as VBackground).Fill = bool.Parse(fill);
                    }

                    if ((tbFill.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbFill.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tbFill.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbFill.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  FillColor
        private void tbFillColor_LostFocus(object sender, RoutedEventArgs e)
        {
            string fillColor = tbFillColor.Text.Trim().ToLower();

            if (Parent is VShapeBase)
            {
                if ((Parent as VShapeBase).FillColor == fillColor || ((Parent as VShapeBase).FillColor == null && fillColor == ""))
                {
                    return;
                }

                if (fillColor == "")
                {
                    (Parent as VShapeBase).FillColor = null;
                }
                else
                {
                    (Parent as VShapeBase).FillColor = fillColor;
                }
            }
            else if (Parent is VBackground)
            {
                if ((Parent as VBackground).FillColor.ToLower() == fillColor || ((Parent as VBackground).FillColor == null && fillColor == ""))
                {
                    return;
                }

                if (fillColor == "")
                {
                    (Parent as VBackground).FillColor = null;
                }
                else
                {
                    (Parent as VBackground).FillColor = fillColor;
                }
            }
        }

        //  V
        private void tbV_LostFocus(object sender, RoutedEventArgs e)
        {
            string v = tbV.Text.Trim();

            if (Parent is VPath)
            {
                if ((Parent as VPath).V == v || ((Parent as VPath).V == null && v == ""))
                {
                    return;
                }
            }

            if (v == "")
            {
                if (Parent is VPath)
                {
                    (Parent as VPath).V = null;
                }
            }
            else
            {
                if (Parent is VPath)
                {
                    (Parent as VPath).V = v;
                }
            }
        }

        //  Print
        private void tbPrint_LostFocus(object sender, RoutedEventArgs e)
        {
            string print = tbPrint.Text.Trim().ToLower();

            if (Parent is VShapeBase)
            {
                if (print == "")
                {
                    tbPrint.Text = "True";
                    (Parent as VShapeBase).Print = true;

                    if ((tbPrint.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbPrint.Background = TrueBrush;
                        numError--;
                    }
                }
                else
                {
                    try
                    {
                        (Parent as VShapeBase).Print = bool.Parse(print);

                        if ((tbPrint.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tbPrint.Background = TrueBrush;
                            numError--;
                        }
                    }
                    catch
                    {
                        if ((tbPrint.Background as SolidColorBrush).Color == TrueColor)
                        {
                            tbPrint.Background = ErrorBrush;
                            numError++;
                        }
                    }
                }

                RefreshError();
            }
        }

        private void pPrint_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pPrint.Visibility == Visibility.Visible)
            {
                string print = tbPrint.Text.Trim().ToLower();

                if (print == "false" || print == "true")
                {
                    tbPrint.Background = TrueBrush;
                }
                else
                {
                    tbPrint.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        //  CoordSize
        private Point ChangePoint(string s)
        {

            string[] arr = s.Split(' ');
            List<int> li = new List<int>();

            foreach (string e in arr)
            {
                try
                {
                    li.Add(int.Parse(e));
                }
                catch
                { }
            }

            if (li.Count() == 2)
            {
                if (MinPoint <= li[0] && li[0] <= MaxPoint && MinPoint <= li[1] && li[1] <= MaxPoint)
                {
                    return new Point(li[0], li[1]);
                }
            }

            return new Point(int.MaxValue, int.MaxValue);
        }

        private Point ChangePoint2(string s)
        {
            if (s == "auto")
            {
                return new Point(int.MinValue, int.MinValue);
            }

            string[] arr = s.Split(' ');
            List<int> li = new List<int>();

            foreach (string e in arr)
            {
                try
                {
                    li.Add(int.Parse(e));
                }
                catch
                { }
            }

            if (li.Count() == 2)
            {
                if (MinPoint <= li[0] && li[0] <= MaxPoint && MinPoint <= li[1] && li[1] <= MaxPoint)
                {
                    return new Point(li[0], li[1]);
                }
            }

            return new Point(int.MaxValue, int.MaxValue);
        }

        private void pCoordSize_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pCoordSize.Visibility == Visibility.Visible)
            {
                string coordSize = tbCoordSize.Text.Trim();
                Point s = ChangePoint(coordSize);

                if (s.X == int.MaxValue)
                {
                    tbCoordSize.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tbCoordSize.Background = TrueBrush;
                }
            }
        }

        private void tbCoordSize_LostFocus(object sender, RoutedEventArgs e)
        {
            string coordSize = tbCoordSize.Text.Trim();
            Point s = ChangePoint(coordSize);

            if (s.X == int.MaxValue)
            {
                if ((tbCoordSize.Background as SolidColorBrush).Color == TrueColor)
                {
                    tbCoordSize.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tbCoordSize.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbCoordSize.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).CoordSize = s;
                    tbCoordSize.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  CoordOrigin
        private void pCoordOrigin_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pCoordOrigin.Visibility == Visibility.Visible)
            {
                string coordOrigin = tbCoordOrigin.Text.Trim();
                Point s = ChangePoint(coordOrigin);

                if (s.X == int.MaxValue)
                {
                    tbCoordOrigin.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tbCoordOrigin.Background = TrueBrush;
                }
            }
        }

        private void tbCoordOrigin_LostFocus(object sender, RoutedEventArgs e)
        {
            string coordOrigin = tbCoordOrigin.Text.Trim();
            Point s = ChangePoint(coordOrigin);

            if (s.X == int.MaxValue)
            {
                if ((tbCoordOrigin.Background as SolidColorBrush).Color == TrueColor)
                {
                    tbCoordOrigin.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tbCoordOrigin.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbCoordOrigin.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VGroupElement)
                {
                    (Parent as VGroupElement).CoordOrigin = s;
                    tbCoordOrigin.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  WrapCoords
        private void tbWrapCoords_LostFocus(object sender, RoutedEventArgs e)
        {
            string wrapCoords = tbWrapCoords.Text.Trim();

            if (Parent is VGroupElement)
            { 
                if(wrapCoords == "")
                {
                    (Parent as VGroupElement).WrapCoords = null;
                }
                else
                {
                    (Parent as VGroupElement).WrapCoords = wrapCoords;
                }
            }
        }

        //  Limo
        private void tbLimo_LostFocus(object sender, RoutedEventArgs e)
        {
            string limo = tbLimo.Text.Trim();
            Point s = ChangePoint(limo);

            if (s.X == int.MaxValue)
            {
                if ((tbLimo.Background as SolidColorBrush).Color == TrueColor)
                {
                    tbLimo.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tbLimo.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbLimo.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VPath)
                {
                    (Parent as VPath).Limo = s;
                    tbLimo.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        private void pLimo_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pLimo.Visibility == Visibility.Visible)
            {
                string limo = tbLimo.Text.Trim();
                Point s = ChangePoint(limo);

                if (s.X == int.MaxValue)
                {
                    tbLimo.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tbLimo.Background = TrueBrush;
                }
            }
        }

        //  FillOk
        private void pFillOk_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFillOk.Visibility == Visibility.Visible)
            {
                string fillOk = tbFillOk.Text.Trim().ToLower();

                if (fillOk == "false" || fillOk == "true")
                {
                    tbFillOk.Background = TrueBrush;
                }
                else
                {
                    tbFillOk.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbFillOk_LostFocus(object sender, RoutedEventArgs e)
        {
            string fillOk = tbFillOk.Text.Trim().ToLower();

            if (fillOk == "")
            {
                tbFillOk.Text = "True";

                if (Parent is VPath)
                {
                    (Parent as VPath).FillOk = true;
                }

                if ((tbFillOk.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbFillOk.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VPath)
                    {
                        (Parent as VPath).FillOk = bool.Parse(fillOk);
                    }

                    if ((tbFillOk.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbFillOk.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tbFillOk.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbFillOk.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  StrokeOk
        private void pStrokeOk_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pStrokeOk.Visibility == Visibility.Visible)
            {
                string strokeOk = tbStrokeOk.Text.Trim().ToLower();

                if (strokeOk == "false" || strokeOk == "true")
                {
                    tbStrokeOk.Background = TrueBrush;
                }
                else
                {
                    tbStrokeOk.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbStrokeOk_LostFocus(object sender, RoutedEventArgs e)
        {
            string strokeOk = tbStrokeOk.Text.Trim().ToLower();

            if (strokeOk == "")
            {
                tbStrokeOk.Text = "True";

                if (Parent is VPath)
                {
                    (Parent as VPath).StrokeOk = true;
                }

                if ((tbStrokeOk.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbStrokeOk.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VPath)
                    {
                        (Parent as VPath).StrokeOk = bool.Parse(strokeOk);
                    }

                    if ((tbStrokeOk.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbStrokeOk.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tbStrokeOk.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbStrokeOk.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  ShadowOk
        private void pShadowOk_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pShadowOk.Visibility == Visibility.Visible)
            {
                string shadowOk = tbShadowOk.Text.Trim().ToLower();

                if (shadowOk == "false" || shadowOk == "true")
                {
                    tbShadowOk.Background = TrueBrush;
                }
                else
                {
                    tbShadowOk.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbShadowOk_LostFocus(object sender, RoutedEventArgs e)
        {
            string shadowOk = tbShadowOk.Text.Trim().ToLower();

            if (shadowOk == "")
            {
                tbShadowOk.Text = "True";

                if (Parent is VPath)
                {
                    (Parent as VPath).ShadowOk = true;
                }

                if ((tbShadowOk.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbShadowOk.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VPath)
                    {
                        (Parent as VPath).ShadowOk = bool.Parse(shadowOk);
                    }

                    if ((tbShadowOk.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbShadowOk.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tbShadowOk.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbShadowOk.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  ArrowOk
        private void pArrowOk_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pArrowOk.Visibility == Visibility.Visible)
            {
                string arrowOk = tbArrowOk.Text.Trim().ToLower();

                if (arrowOk == "false" || arrowOk == "true")
                {
                    tbArrowOk.Background = TrueBrush;
                }
                else
                {
                    tbArrowOk.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbArrowOk_LostFocus(object sender, RoutedEventArgs e)
        {
            string arrowOk = tbArrowOk.Text.Trim().ToLower();

            if (arrowOk == "")
            {
                tbArrowOk.Text = "False";

                if (Parent is VPath)
                {
                    (Parent as VPath).ArrowOk = false;
                }

                if ((tbArrowOk.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbArrowOk.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VPath)
                    {
                        (Parent as VPath).ArrowOk = bool.Parse(arrowOk);
                    }

                    if ((tbArrowOk.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbArrowOk.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tbArrowOk.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbArrowOk.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  GradientShapeOk
        private void pGradientShapeOk_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pGradientShapeOk.Visibility == Visibility.Visible)
            {
                string gradientShapeOk = tbGradientShapeOk.Text.Trim().ToLower();

                if (gradientShapeOk == "false" || gradientShapeOk == "true")
                {
                    tbGradientShapeOk.Background = TrueBrush;
                }
                else
                {
                    tbGradientShapeOk.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbGradientShapeOk_LostFocus(object sender, RoutedEventArgs e)
        {
            string gradientShapeOk = tbGradientShapeOk.Text.Trim().ToLower();

            if (gradientShapeOk == "")
            {
                tbGradientShapeOk.Text = "False";

                if (Parent is VPath)
                {
                    (Parent as VPath).GradientShapeOK = false;
                }

                if ((tbGradientShapeOk.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbGradientShapeOk.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VPath)
                    {
                        (Parent as VPath).GradientShapeOK = bool.Parse(gradientShapeOk);
                    }

                    if ((tbGradientShapeOk.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbGradientShapeOk.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tbGradientShapeOk.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbGradientShapeOk.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  TextPathOk
        private void pTextPathOk_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pTextPathOk.Visibility == Visibility.Visible)
            {
                string textPathOk = tbTextPathOk.Text.Trim().ToLower();

                if (textPathOk == "false" || textPathOk == "true")
                {
                    tbTextPathOk.Background = TrueBrush;
                }
                else
                {
                    tbTextPathOk.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbTextPathOk_LostFocus(object sender, RoutedEventArgs e)
        {
            string textPathOk = tbTextPathOk.Text.Trim().ToLower();

            if (textPathOk == "")
            {
                tbTextPathOk.Text = "False";

                if (Parent is VPath)
                {
                    (Parent as VPath).TextPathOK = false;
                }

                if ((tbTextPathOk.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbTextPathOk.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VPath)
                    {
                        (Parent as VPath).TextPathOK = bool.Parse(textPathOk);
                    }

                    if ((tbTextPathOk.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tbTextPathOk.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tbTextPathOk.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tbTextPathOk.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  TextBoxRect
        private void tbTextBoxRect_LostFocus(object sender, RoutedEventArgs e)
        {
            string textBoxRect = tbTextBoxRect.Text.Trim();

            if (Parent is VPath)
            {
                if (textBoxRect == "")
                {
                    (Parent as VPath).TextBoxRect = null;
                }
                else
                {
                    (Parent as VPath).TextBoxRect = textBoxRect;
                }
            }
        }

        //  Eqn
        private void tbEqn_LostFocus(object sender, RoutedEventArgs e)
        {
            string eqn = tbEqn.Text.Trim();

            if (Parent is VF)
            {
                if (eqn == "")
                {
                    (Parent as VF).eqn = null;
                }
                else
                {
                    (Parent as VF).eqn = eqn;
                }
            }
        }

        //  Position
        private void pPosition_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pPosition.Visibility == Visibility.Visible)
            {
                TextBox tb = tbPosition;
                string str = tb.Text.Trim();
                Point s;

                if (Parent is VFill)
                {
                    s = ChangePoint2(str);
                }
                else
                {
                    s = ChangePoint(str);
                }

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbPosition_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbPosition;
            string str = tb.Text.Trim();
            Point s;

            if (Parent is VFill)
            {
                s = ChangePoint2(str);
            }
            else
            {
                s = ChangePoint(str);
            }

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VH)
                {
                    (Parent as VH).Position = s;
                    tb.Text = s.X + " " + s.Y;
                }
                else if (Parent is VFill)
                {
                    if (s.X == int.MinValue)
                    {
                        (Parent as VFill).Position = s;
                        tb.Text = "auto";
                    }
                    else
                    {
                        (Parent as VFill).Position = s;
                        tb.Text = s.X + " " + s.Y;
                    }
                }
            }

            RefreshError();
        }

        //  Map
        private void pMap_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pMap.Visibility == Visibility.Visible)
            {
                TextBox tb = tbMap;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbMap_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbMap;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VH)
                {
                    (Parent as VH).Map = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  XRange
        private void pXRange_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pXRange.Visibility == Visibility.Visible)
            {
                TextBox tb = tbXRange;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbXRange_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbXRange;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VH)
                {
                    (Parent as VH).XRange = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  YRange
        private void pYRange_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pYRange.Visibility == Visibility.Visible)
            {
                TextBox tb = tbYRange;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbYRange_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbYRange;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VH)
                {
                    (Parent as VH).YRange = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  RadiusRange
        private void pRadiusRange_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pRadiusRange.Visibility == Visibility.Visible)
            {
                TextBox tb = tbRadiusRange;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbRadiusRange_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbRadiusRange;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VH)
                {
                    (Parent as VH).RadiusRange = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  Size
        private void pSize_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pSize.Visibility == Visibility.Visible)
            {
                TextBox tb = tbSize;
                string str = tb.Text.Trim();

                Point s = ChangePoint2(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbSize_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbSize;
            string str = tb.Text.Trim();

            Point s = ChangePoint2(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VFill)
                {
                    if (s.X == int.MinValue)
                    {
                        (Parent as VFill).Size = s;
                        tb.Text = "auto";
                    }
                    else
                    {
                        (Parent as VFill).Size = s;
                        tb.Text = s.X + " " + s.Y;
                    }
                }
            }

            RefreshError();
        }

        //  Origin
        private void pOrigin_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pOrigin.Visibility == Visibility.Visible)
            {
                TextBox tb = tbOrigin;
                string str = tb.Text.Trim();
                Point s;

                if (Parent is VFill)
                {
                    s = ChangePoint2(str);
                }
                else
                {
                    s = ChangePoint(str);
                }

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbOrigin_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbOrigin;
            string str = tb.Text.Trim();
            Point s;

            if (Parent is VFill)
            {
                s = ChangePoint2(str);
            }
            else
            {
                s = ChangePoint(str);
            }

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VFill)
                {
                    if (s.X == int.MinValue)
                    {
                        (Parent as VFill).Origin = s;
                        tb.Text = "auto";
                    }
                    else
                    {
                        (Parent as VFill).Origin = s;
                        tb.Text = s.X + " " + s.Y;
                    }
                }
                else if (Parent is VShadow)
                {
                    (Parent as VShadow).Origin = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  FocusSize
        private void pFocusSize_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFocusSize.Visibility == Visibility.Visible)
            {
                TextBox tb = tbFocusSize;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbFocusSize_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbFocusSize;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VFill)
                {
                    (Parent as VFill).FocusSize = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  FocusPosition
        private void pFocusPosition_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFocusPosition.Visibility == Visibility.Visible)
            {
                TextBox tb = tbFocusPosition;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbFocusPosition_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbFocusPosition;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VFill)
                {
                    (Parent as VFill).FocusPosition = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  ImageSize
        private void pImageSize_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pImageSize.Visibility == Visibility.Visible)
            {
                TextBox tb = tbImageSize;
                string str = tb.Text.Trim();

                Point s = ChangePoint2(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbImageSize_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbImageSize;
            string str = tb.Text.Trim();

            Point s = ChangePoint2(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VStroke)
                {
                    if (s.X == int.MinValue)
                    {
                        (Parent as VStroke).ImageSize = s;
                        tb.Text = "auto";
                    }
                    else
                    {
                        (Parent as VStroke).ImageSize = s;
                        tb.Text = s.X + " " + s.Y;
                    }
                }
            }

            RefreshError();
        }

        //  Offset
        private void pOffset_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pOffset.Visibility == Visibility.Visible)
            {
                TextBox tb = tbOffset;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbOffset_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbOffset;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VShadow)
                {
                    (Parent as VShadow).Offset = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  Offset2
        private void pOffset2_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pOffset2.Visibility == Visibility.Visible)
            {
                TextBox tb = tbOffset2;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbOffset2_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbOffset2;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VShadow)
                {
                    (Parent as VShadow).Offset2 = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  From
        private void pFrom_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFrom.Visibility == Visibility.Visible)
            {
                TextBox tb = tbFrom;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbFrom_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbFrom;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VLine)
                {
                    (Parent as VLine).From = s;
                    tb.Text = s.X + " " + s.Y;
                }
                else if (Parent is VCurve)
                {
                    (Parent as VCurve).From = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  To
        private void pTo_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pTo.Visibility == Visibility.Visible)
            {
                TextBox tb = tbTo;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbTo_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbTo;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VLine)
                {
                    (Parent as VLine).To = s;
                    tb.Text = s.X + " " + s.Y;
                }
                else if (Parent is VCurve)
                {
                    (Parent as VCurve).To = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  Control1
        private void pControl1_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pControl1.Visibility == Visibility.Visible)
            {
                TextBox tb = tbControl1;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbControl1_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbControl1;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VCurve)
                {
                    (Parent as VCurve).Control1 = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  Control2
        private void pControl2_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pControl2.Visibility == Visibility.Visible)
            {
                TextBox tb = tbControl2;
                string str = tb.Text.Trim();

                Point s = ChangePoint(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbControl2_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbControl2;
            string str = tb.Text.Trim();

            Point s = ChangePoint(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VCurve)
                {
                    (Parent as VCurve).Control2 = s;
                    tb.Text = s.X + " " + s.Y;
                }
            }

            RefreshError();
        }

        //  Polar
        private void pPolar_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pPolar.Visibility == Visibility.Visible)
            {
                TextBox tb = tbPolar;
                string str = tb.Text.Trim();

                Point s = ChangePoint2(str);

                if (s.X == int.MaxValue)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
                else
                {
                    tb.Background = TrueBrush;
                }
            }
        }

        private void tbPolar_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbPolar;
            string str = tb.Text.Trim();

            Point s = ChangePoint2(str);

            if (s.X == int.MaxValue)
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                if (Parent is VH)
                {
                    if (s.X == int.MinValue)
                    {
                        (Parent as VH).Polar = s;
                        tb.Text = "auto";
                    }
                    else
                    {
                        (Parent as VH).Polar = s;
                        tb.Text = s.X + " " + s.Y;
                    }
                }
            }

            RefreshError();
        }

        //  InvX
        private void pInvX_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pInvX.Visibility == Visibility.Visible)
            {
                TextBox tb = tbInvX;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbInvX_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbInvX;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VH)
                {
                    (Parent as VH).InvX = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VH)
                    {
                        (Parent as VH).InvX = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  InvY
        private void pInvY_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pInvY.Visibility == Visibility.Visible)
            {
                TextBox tb = tbInvY;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbInvY_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbInvY;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VH)
                {
                    (Parent as VH).InvY = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VH)
                    {
                        (Parent as VH).InvY = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  Switch
        private void pSwitch_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pSwitch.Visibility == Visibility.Visible)
            {
                TextBox tb = tbSwitch;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbSwitch_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbSwitch;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VH)
                {
                    (Parent as VH).Switch = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VH)
                    {
                        (Parent as VH).Switch = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  On
        private void pOn_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pOn.Visibility == Visibility.Visible)
            {
                TextBox tb = tbOn;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbOn_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbOn;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                if (Parent is VFill)
                {
                    tb.Text = "True";
                    (Parent as VFill).On = true;
                }
                else if (Parent is VStroke)
                {
                    tb.Text = "True";
                    (Parent as VStroke).On = true;
                }
                else if (Parent is VShadow)
                {
                    tb.Text = "True";
                    (Parent as VShadow).On = true;
                }
                else if (Parent is VTextPath)
                {
                    tb.Text = "False";
                    (Parent as VTextPath).On = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VFill)
                    {
                        (Parent as VFill).On = bool.Parse(str);
                    }
                    else if (Parent is VStroke)
                    {
                        (Parent as VStroke).On = bool.Parse(str);
                    }
                    else if (Parent is VShadow)
                    {
                        (Parent as VShadow).On = bool.Parse(str);
                    }
                    else if (Parent is VTextPath)
                    {
                        (Parent as VTextPath).On = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  AlignShape
        private void pAlignShape_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pAlignShape.Visibility == Visibility.Visible)
            {
                TextBox tb = tbAlignShape;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbAlignShape_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbAlignShape;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "True";

                if (Parent is VFill)
                {
                    (Parent as VFill).AlignShape = true;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VFill)
                    {
                        (Parent as VFill).AlignShape = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  ImageAlignShape
        private void pImageAlignShape_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pImageAlignShape.Visibility == Visibility.Visible)
            {
                TextBox tb = tbImageAlignShape;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbImageAlignShape_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbImageAlignShape;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "True";

                if (Parent is VStroke)
                {
                    (Parent as VStroke).ImageAlignShape = true;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VStroke)
                    {
                        (Parent as VStroke).ImageAlignShape = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  Obscured
        private void pObscured_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pObscured.Visibility == Visibility.Visible)
            {
                TextBox tb = tbObscured;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbObscured_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbObscured;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VShadow)
                {
                    (Parent as VShadow).Obscured  = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VShadow)
                    {
                        (Parent as VShadow).Obscured = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  FitShape
        private void pFitShape_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFitShape.Visibility == Visibility.Visible)
            {
                TextBox tb = tbFitShape;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbFitShape_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbFitShape;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VTextPath)
                {
                    (Parent as VTextPath).FitShape = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VTextPath)
                    {
                        (Parent as VTextPath).FitShape = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  FitPath
        private void pFitPath_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFitPath.Visibility == Visibility.Visible)
            {
                TextBox tb = tbFitPath;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbFitPath_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbFitPath;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VTextPath)
                {
                    (Parent as VTextPath).FitPath = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VTextPath)
                    {
                        (Parent as VTextPath).FitPath = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  Trim
        private void pTrim_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pTrim.Visibility == Visibility.Visible)
            {
                TextBox tb = tbTrim;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbTrim_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbTrim;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VTextPath)
                {
                    (Parent as VTextPath).Trim = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VTextPath)
                    {
                        (Parent as VTextPath).Trim = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  XScale
        private void pXScale_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pXScale.Visibility == Visibility.Visible)
            {
                TextBox tb = tbXScale;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbXScale_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbXScale;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VTextPath)
                {
                    (Parent as VTextPath).XScale = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VTextPath)
                    {
                        (Parent as VTextPath).XScale = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  GrayScale
        private void pGrayScale_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pGrayScale.Visibility == Visibility.Visible)
            {
                TextBox tb = tbGrayScale;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbGrayScale_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbGrayScale;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VImage)
                {
                    (Parent as VImage).GrayScale = false;
                }
                else if (Parent is VImageData)
                {
                    (Parent as VImageData).GrayScale = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VImage)
                    {
                        (Parent as VImage).GrayScale = bool.Parse(str);
                    }
                    else if (Parent is VImageData)
                    {
                        (Parent as VImageData).GrayScale = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  Bilevel
        private void pBilevel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pBilevel.Visibility == Visibility.Visible)
            {
                TextBox tb = tbBilevel;
                string str = tb.Text.Trim().ToLower();

                if (str == "false" || str == "true")
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbBilevel_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbBilevel;
            string str = tb.Text.Trim().ToLower();

            if (str == "")
            {
                tb.Text = "False";

                if (Parent is VImage)
                {
                    (Parent as VImage).Bilevel = false;
                }
                else if (Parent is VImageData)
                {
                    (Parent as VImageData).Bilevel = false;
                }

                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }
            }
            else
            {
                try
                {
                    if (Parent is VImage)
                    {
                        (Parent as VImage).Bilevel = bool.Parse(str);
                    }
                    else if (Parent is VImageData)
                    {
                        (Parent as VImageData).Bilevel = bool.Parse(str);
                    }

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }
                }
                catch
                {
                    if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
            }

            RefreshError();
        }

        //  Color
        private void tbColor_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbColor.Text.Trim();

            if (Parent is VShadow)
            {
                if (str == "")
                {
                    (Parent as VShadow).Color = null;
                }
                else
                {
                    (Parent as VShadow).Color = str;
                }
            }
            else if (Parent is VFill)
            {
                if (str == "")
                {
                    (Parent as VFill).Color = null;
                }
                else
                {
                    (Parent as VFill).Color = str;
                }
            }
            else if (Parent is VStroke)
            {
                if (str == "")
                {
                    (Parent as VStroke).Color = null;
                }
                else
                {
                    (Parent as VStroke).Color = str;
                }
            }
        }

        //  Color2
        private void tbColor2_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbColor2.Text.Trim();

            if (Parent is VShadow)
            {
                if (str == "")
                {
                    (Parent as VShadow).Color2 = null;
                }
                else
                {
                    (Parent as VShadow).Color2 = str;
                }
            }
            else if (Parent is VFill)
            {
                if (str == "")
                {
                    (Parent as VFill).Color2 = null;
                }
                else
                {
                    (Parent as VFill).Color2 = str;
                }
            }
            else if (Parent is VStroke)
            {
                if (str == "")
                {
                    (Parent as VStroke).Color2 = null;
                }
                else
                {
                    (Parent as VStroke).Color2 = str;
                }
            }
        }

        //  Src
        private void tbSrc_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbSrc.Text.Trim();

            if (Parent is VFill)
            {
                if (str == "")
                {
                    (Parent as VFill).Src = null;
                }
                else
                {
                    (Parent as VFill).Src = str;
                }
            }
            else if (Parent is VStroke)
            {
                if (str == "")
                {
                    (Parent as VStroke).Src = null;
                }
                else
                {
                    (Parent as VStroke).Src = str;
                }
            }
            else if (Parent is VImageData)
            {
                if (str == "")
                {
                    (Parent as VImageData).Src = null;
                }
                else
                {
                    (Parent as VImageData).Src = str;
                }
            }
            else if (Parent is VImage)
            {
                if (str == "")
                {
                    (Parent as VImage).Src = null;
                }
                else
                {
                    (Parent as VImage).Src = str;
                }
            }
        }

        //  Aspect
        private bool CheckAspect(string aspect)
        {
            if (Parent is VFill)
            {
                if (aspect == "")
                {
                    tbAspect.Text = "ignore";
                    return true;
                }

                string[] t = { "ignore", "atleast", "atmost"};

                foreach (var obj in t)
                {
                    if (aspect == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pAspect_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pAspect.Visibility == Visibility.Visible)
            { 
                string aspect = tbAspect.Text.Trim().ToLower();

                if (CheckAspect(aspect))
                {
                    tbAspect.Background = TrueBrush;
                }
                else
                {
                    tbAspect.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbAspect_LostFocus(object sender, RoutedEventArgs e)
        {
            string aspect = tbAspect.Text.Trim().ToLower();

            if (CheckAspect(aspect))
            {
                if ((tbAspect.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbAspect.Background = TrueBrush;
                    numError--;
                }

                (Parent as VFill).Aspect = aspect;
            }
            else
            {
                if ((tbAspect.Background as SolidColorBrush).Color == TrueColor)
                {
                    tbAspect.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  Colors
        private void tbColors_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbColors.Text.Trim();

            if (Parent is VFill)
            {
                if (str == "")
                {
                    (Parent as VFill).Colors = null;
                }
                else
                {
                    (Parent as VFill).Colors = str;
                }
            }
        }

        //  Method
        private bool CheckMethod(string method)
        {
            if (Parent is VFill)
            {
                if (method == "")
                {
                    tbMethod.Text = "sigma";
                    return true;
                }

                string[] arr = method.Split();
                bool isLinear = false;
                bool isSigma = false;

                foreach (var i in arr)
                {
                    switch (i)
                    {
                        case "":
                            break;
                        case "linear":
                            isLinear = true;
                            break;
                        case "sigma":
                            isSigma = true;
                            break;
                    }
                }

                if (isLinear && isSigma)
                {
                    tbMethod.Text = "linear sigma";
                    return true;
                }

                string[] t = { "none", "linear", "sigma", "any"};

                foreach (var obj in t)
                {
                    if (method == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pMethod_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pMethod.Visibility == Visibility.Visible)
            {
                string method = tbMethod.Text.Trim().ToLower();

                if (CheckMethod(method))
                {
                    tbMethod.Background = TrueBrush;
                }
                else
                {
                    tbMethod.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbMethod_LostFocus(object sender, RoutedEventArgs e)
        {
            string method = tbMethod.Text.Trim().ToLower();

            if (CheckMethod(method))
            {
                if ((tbMethod.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbMethod.Background = TrueBrush;
                    numError--;
                }

                (Parent as VFill).Method = method;
            }
            else
            {
                if ((tbMethod.Background as SolidColorBrush).Color == TrueColor)
                {
                    tbMethod.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  Style
        private void tbStyle_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbStyle.Text.Trim();

            if (Parent is VGroupElement)
            {
                if (str == "")
                {
                    (Parent as VGroupElement).Style = null;
                }
                else
                {
                    (Parent as VGroupElement).Style = str;
                }
            }
            else if (Parent is VStroke)
            {
                if (str == "")
                {
                    (Parent as VStroke).Style = null;
                }
                else
                {
                    (Parent as VStroke).Style = str;
                }
            }
            else if (Parent is VTextBox)
            {
                if (str == "")
                {
                    (Parent as VTextBox).Style = null;
                }
                else
                {
                    (Parent as VTextBox).Style = str;
                }
            }
            else if (Parent is VTextPath)
            {
                if (str == "")
                {
                    (Parent as VTextPath).Style = null;
                }
                else
                {
                    (Parent as VTextPath).Style = str;
                }
            }
        }

        //  JoinStyle
        private bool CheckJoinStyle(string joinStyle)
        {
            if (Parent is VStroke)
            {
                if (joinStyle == "")
                {
                    tbJoinStyle.Text = "round";
                    return true;
                }

                string[] t = { "round", "bevel", "miter" };

                foreach (var obj in t)
                {
                    if (joinStyle == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pJoinStyle_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pJoinStyle.Visibility == Visibility.Visible)
            {
                string joinStyle = tbJoinStyle.Text.Trim().ToLower();

                if (CheckJoinStyle(joinStyle))
                {
                    tbJoinStyle.Background = TrueBrush;
                }
                else
                {
                    tbJoinStyle.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbJoinStyle_LostFocus(object sender, RoutedEventArgs e)
        {
            string joinStyle = tbJoinStyle.Text.Trim().ToLower();

            if (CheckJoinStyle(joinStyle))
            {
                if ((tbJoinStyle.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tbJoinStyle.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).JoinStyle = joinStyle;
            }
            else
            {
                if ((tbJoinStyle.Background as SolidColorBrush).Color == TrueColor)
                {
                    tbJoinStyle.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  EndCap
        private bool CheckEndCap(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbEndCap.Text = "round";
                    return true;
                }

                string[] t = { "round", "flat", "square" };

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pEndCap_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pEndCap.Visibility == Visibility.Visible)
            {
                TextBox tb = tbEndCap;
                string str = tb.Text.Trim().ToLower();

                if (CheckEndCap(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbEndCap_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbEndCap;
            string str = tb.Text.Trim().ToLower();

            if (CheckEndCap(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).EndCap = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  DashStyle
        private bool CheckDashStyle(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbDashStyle.Text = "solid";
                    return true;
                }

                string[] t = { "solid", "dot", "dash", "dashdot", "longdash", "longdashdot", "longdashdotdot"};

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pDashStyle_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pDashStyle.Visibility == Visibility.Visible)
            {
                TextBox tb = tbDashStyle;
                string str = tb.Text.Trim().ToLower();

                if (CheckDashStyle(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbDashStyle_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbDashStyle;
            string str = tb.Text.Trim().ToLower();

            if (CheckDashStyle(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).DashStyle = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  FillType
        private bool CheckFillType(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbFillType.Text = "solid";
                    return true;
                }

                string[] t = { "solid", "tile", "pattern", "frame"};

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pFillType_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFillType.Visibility == Visibility.Visible)
            {
                TextBox tb = tbFillType;
                string str = tb.Text.Trim().ToLower();

                if (CheckFillType(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbFillType_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbFillType;
            string str = tb.Text.Trim().ToLower();

            if (CheckFillType(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).FillType = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  StartArrow
        private bool CheckStartArrow(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbStartArrow.Text = "none";
                    return true;
                }

                string[] t = { "none", "block", "classic", "diamond", "oval", "open", "chevron", "doublechevron" };

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pStartArrow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pStartArrow.Visibility == Visibility.Visible)
            {
                TextBox tb = tbStartArrow;
                string str = tb.Text.Trim().ToLower();

                if (CheckStartArrow(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbStartArrow_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbStartArrow;
            string str = tb.Text.Trim().ToLower();

            if (CheckStartArrow(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).StartArrow = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  StartArrowWidth
        private bool CheckStartArrowWidth(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbStartArrowWidth.Text = "medium";
                    return true;
                }

                string[] t = { "narrow", "medium", "wide" };

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pStartArrowWidth_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pStartArrowWidth.Visibility == Visibility.Visible)
            {
                TextBox tb = tbStartArrowWidth;
                string str = tb.Text.Trim().ToLower();

                if (CheckStartArrowWidth(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbStartArrowWidth_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbStartArrowWidth;
            string str = tb.Text.Trim().ToLower();

            if (CheckStartArrowWidth(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).StartArrowWidth = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  StartArrowLength
        private bool CheckStartArrowLength(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbStartArrowLength.Text = "medium";
                    return true;
                }

                string[] t = { "short",  "medium", "long" };

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pStartArrowLength_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pStartArrowLength.Visibility == Visibility.Visible)
            {
                TextBox tb = tbStartArrowLength;
                string str = tb.Text.Trim().ToLower();

                if (CheckStartArrowLength(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbStartArrowLength_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbStartArrowLength;
            string str = tb.Text.Trim().ToLower();

            if (CheckStartArrowLength(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).StartArrowLength = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  EndArrow
        private bool CheckEndArrow(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbEndArrow.Text = "none";
                    return true;
                }

                string[] t = { "none", "block", "classic", "diamond", "oval", "open", "chevron", "doublechevron" };

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pEndArrow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pEndArrow.Visibility == Visibility.Visible)
            {
                TextBox tb = tbEndArrow;
                string str = tb.Text.Trim().ToLower();

                if (CheckEndArrow(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbEndArrow_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbEndArrow;
            string str = tb.Text.Trim().ToLower();

            if (CheckEndArrow(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).EndArrow = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  EndArrowWidth
        private bool CheckEndArrowWidth(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbEndArrowWidth.Text = "medium";
                    return true;
                }

                string[] t = { "narrow", "medium", "wide" };

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pEndArrowWidth_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pEndArrowWidth.Visibility == Visibility.Visible)
            {
                TextBox tb = tbEndArrowWidth;
                string str = tb.Text.Trim().ToLower();

                if (CheckEndArrowWidth(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbEndArrowWidth_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbEndArrowWidth;
            string str = tb.Text.Trim().ToLower();

            if (CheckEndArrowWidth(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).EndArrowWidth = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  EndArrowLength
        private bool CheckEndArrowLength(string str)
        {
            if (Parent is VStroke)
            {
                if (str == "")
                {
                    tbEndArrowLength.Text = "medium";
                    return true;
                }

                string[] t = { "short", "medium", "long" };

                foreach (var obj in t)
                {
                    if (str == obj)
                        return true;
                }

                return false;
            }

            return false;
        }

        private void pEndArrowLength_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pEndArrowLength.Visibility == Visibility.Visible)
            {
                TextBox tb = tbEndArrowLength;
                string str = tb.Text.Trim().ToLower();

                if (CheckEndArrowLength(str))
                {
                    tb.Background = TrueBrush;
                }
                else
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }
        
        private void tbEndArrowLength_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox tb = tbEndArrowLength;
            string str = tb.Text.Trim().ToLower();

            if (CheckEndArrowLength(str))
            {
                if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                {
                    tb.Background = TrueBrush;
                    numError--;
                }

                (Parent as VStroke).EndArrowLength = str;
            }
            else
            {
                if ((tb.Background as SolidColorBrush).Color == TrueColor)
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }

            RefreshError();
        }

        //  Matrix
        private void tbMatrix_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbMatrix.Text.Trim();

            if (Parent is VShadow)
            {
                if (str == "")
                {
                    (Parent as VShadow).Matrix = null;
                }
                else
                {
                    (Parent as VShadow).Matrix = str;
                }
            }
        }

        //  String
        private void tbString_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbString.Text.Trim();

            if (Parent is VTextPath)
            {
                if (str == "")
                {
                    (Parent as VTextPath).String = null;
                }
                else
                {
                    (Parent as VTextPath).String = str;
                }
            }
        }

        //  Points
        private bool CheckPoints(string str)
        {
            return true;
        }

        private void pPoints_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {

        }

        private void tbPoints_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbPoints.Text.Trim();

            if (Parent is VPolyLine)
            {
                if (str == "")
                {
                    (Parent as VPolyLine).Points = null;
                }
                else
                {
                    //(Parent as VPolyLine).Points = str;
                }
            }
        }

        //  Angle
        private void tbAngle_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbAngle;
            string result = "";

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pAngle_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pAngle.Visibility == Visibility.Visible)
            {
                TextBox tb = tbAngle;

                try
                {
                    int v = int.Parse(tb.Text);

                    if (0 <= v && v <= 360)
                    {
                        tb.Background = TrueBrush;
                    }
                    else
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbAngle_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VFill)
            {
                TextBox tb = tbAngle;

                try
                {
                    int v = int.Parse(tb.Text);

                    if (0 <= v && v <= 360)
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        (Parent as VFill).Angle = v;
                    }
                    else
                    {
                        if ((tb.Background as SolidColorBrush).Color == TrueColor)
                        {
                            tb.Background = ErrorBrush;
                            numError++;
                        }
                    }

                    
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0";
                        (Parent as VFill).Angle = 0;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  Focus
        private void tbFocus_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbFocus;
            string result = "";
            bool checkDot = true;

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '-' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pFocus_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pFocus.Visibility == Visibility.Visible)
            {
                TextBox tb = tbFocus;

                try
                {
                    int v = int.Parse(tb.Text);

                    if (-100 <= v && v <= 100)
                    {
                        tb.Background = TrueBrush;
                    }
                    else
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbFocus_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VFill)
            {
                TextBox tb = tbFocus;

                try
                {
                    int v = int.Parse(tb.Text);

                    if (-100 <= v && v <= 100)
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        (Parent as VFill).Focus = v;
                    }
                    else
                    {
                        if ((tb.Background as SolidColorBrush).Color == TrueColor)
                        {
                            tb.Background = ErrorBrush;
                            numError++;
                        }
                    }


                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0";
                        (Parent as VFill).Focus = 0;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  Weight
        private void tbWeight_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbWeight;
            string result = "";
            bool checkDot = true;

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '.' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pWeight_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pWeight.Visibility == Visibility.Visible)
            {
                TextBox tb = tbWeight;

                try
                {
                    float weight = float.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbWeight_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VStroke)
            {
                TextBox tb = tbWeight;

                try
                {
                    float v = float.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    (Parent as VStroke).Weight = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "1";
                        (Parent as VStroke).Weight = 1;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  MiterLimit
        private void tbMiterLimit_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbMiterLimit;
            string result = "";
            bool checkDot = true;

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '.' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pMiterLimit_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pMiterLimit.Visibility == Visibility.Visible)
            {
                TextBox tb = tbMiterLimit;

                try
                {
                    float weight = float.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbMiterLimit_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VStroke)
            {
                TextBox tb = tbMiterLimit;

                try
                {
                    float v = float.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    (Parent as VStroke).MiterLimit = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "8.0";
                        (Parent as VStroke).MiterLimit = 8.0f;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  CropLeft
        private void tbCropLeft_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbCropLeft;
            string result = "";

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pCropLeft_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pCropLeft.Visibility == Visibility.Visible)
            {
                TextBox tb = tbCropLeft;

                try
                {
                    int weight = int.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbCropLeft_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VImageData || Parent is VImage)
            {
                TextBox tb = tbCropLeft;

                try
                {
                    int v = int.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    if(Parent is VImageData)
                        (Parent as VImageData).CropLeft = v;
                    else
                        (Parent as VImage).CropLeft = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0";
                        if (Parent is VImageData)
                            (Parent as VImageData).CropLeft = 0;
                        else
                            (Parent as VImage).CropLeft = 0;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  CropTop
        private void tbCropTop_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbCropTop;
            string result = "";

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pCropTop_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pCropTop.Visibility == Visibility.Visible)
            {
                TextBox tb = tbCropTop;

                try
                {
                    int weight = int.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbCropTop_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VImageData || Parent is VImage)
            {
                TextBox tb = tbCropTop;

                try
                {
                    int v = int.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    if (Parent is VImageData)
                        (Parent as VImageData).CropTop = v;
                    else
                        (Parent as VImage).CropTop = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0";
                        if (Parent is VImageData)
                            (Parent as VImageData).CropTop = 0;
                        else
                            (Parent as VImage).CropTop = 0;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //CropRight
        private void tbCropRight_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbCropRight;
            string result = "";

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pCropRight_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pCropRight.Visibility == Visibility.Visible)
            {
                TextBox tb = tbCropRight;

                try
                {
                    int weight = int.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbCropRight_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VImageData || Parent is VImage)
            {
                TextBox tb = tbCropRight;

                try
                {
                    int v = int.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    if (Parent is VImageData)
                        (Parent as VImageData).CropRight = v;
                    else
                        (Parent as VImage).CropRight = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0";
                        if (Parent is VImageData)
                            (Parent as VImageData).CropRight = 0;
                        else
                            (Parent as VImage).CropRight = 0;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  CropBottom
        private void tbCropBottom_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbCropBottom;
            string result = "";

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pCropBottom_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pCropBottom.Visibility == Visibility.Visible)
            {
                TextBox tb = tbCropBottom;

                try
                {
                    int weight = int.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbCropBottom_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VImageData || Parent is VImage)
            {
                TextBox tb = tbCropBottom;

                try
                {
                    int v = int.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    if (Parent is VImageData)
                        (Parent as VImageData).CropBottom = v;
                    else
                        (Parent as VImage).CropBottom = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0";
                        if (Parent is VImageData)
                            (Parent as VImageData).CropBottom = 0;
                        else
                            (Parent as VImage).CropBottom = 0;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  Gain
        private void tbGain_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbGain;
            string result = "";
            bool checkDot = true;

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '.' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pGain_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pGain.Visibility == Visibility.Visible)
            {
                TextBox tb = tbGain;

                try
                {
                    float weight = float.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbGain_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VImageData || Parent is VImage)
            {
                TextBox tb = tbGain;

                try
                {
                    float v = float.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    if (Parent is VImageData)
                        (Parent as VImageData).Gain = v;
                    else
                        (Parent as VImage).Gain = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "1";
                        if (Parent is VImageData)
                            (Parent as VImageData).Gain = 1;
                        else
                            (Parent as VImage).Gain = 1;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  BlackLevel
        private void tbBlackLevel_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbBlackLevel;
            string result = "";
            bool checkDot = true;
            bool checkNe = true;

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '.' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
                else if (c == '-' && checkNe)
                {
                    result += c;
                    checkNe = false;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pBlackLevel_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pBlackLevel.Visibility == Visibility.Visible)
            {
                TextBox tb = tbBlackLevel;

                try
                {
                    float weight = float.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbBlackLevel_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VImageData || Parent is VImage)
            {
                TextBox tb = tbBlackLevel;

                try
                {
                    float v = float.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    if (Parent is VImageData)
                        (Parent as VImageData).BlackLevel = v;
                    else
                        (Parent as VImage).BlackLevel = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0";
                        if (Parent is VImageData)
                            (Parent as VImageData).BlackLevel = 0;
                        else
                            (Parent as VImage).BlackLevel = 0;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  Gamma
        private void tbGamma_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbGamma;
            string result = "";
            bool checkDot = true;
            bool checkNe = true;

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '.' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
                else if (c == '-' && checkNe)
                {
                    result += c;
                    checkNe = false;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pGamma_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pGamma.Visibility == Visibility.Visible)
            {
                TextBox tb = tbGamma;

                try
                {
                    float weight = float.Parse(tb.Text);

                    tb.Background = TrueBrush;
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbGamma_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VImageData || Parent is VImage)
            {
                TextBox tb = tbGamma;

                try
                {
                    float v = float.Parse(tb.Text);

                    if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                    {
                        tb.Background = TrueBrush;
                        numError--;
                    }

                    if (Parent is VImageData)
                        (Parent as VImageData).Gamma = v;
                    else
                        (Parent as VImage).Gamma = v;
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "1";
                        if (Parent is VImageData)
                            (Parent as VImageData).Gamma = 1;
                        else
                            (Parent as VImage).Gamma = 1;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  ArcSize
        private void tbArcSize_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbArcSize;
            string result = "";
            bool checkDot = true;

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
                else if (c == '.' && checkDot)
                {
                    result += c;
                    checkDot = false;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pArcSize_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pArcSize.Visibility == Visibility.Visible)
            {
                TextBox tb = tbArcSize;

                try
                {
                    float v = float.Parse(tb.Text);

                    if (0 <= v && v <= 1)
                    {
                        tb.Background = TrueBrush;
                    }
                    else
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbArcSize_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VRoundRect)
            {
                TextBox tb = tbArcSize;

                try
                {
                    float v = float.Parse(tb.Text);

                    if (0 <= v && v <= 1)
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        (Parent as VRoundRect).ArcSize = v;
                    }
                    else
                    {
                        if ((tb.Background as SolidColorBrush).Color == TrueColor)
                        {
                            tb.Background = ErrorBrush;
                            numError++;
                        }
                    }

                    
                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0.2";
                        (Parent as VRoundRect).ArcSize = 0.2f;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  StartAngle
        private void tbStartAngle_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbStartAngle;
            string result = "";

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pStartAngle_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pStartAngle.Visibility == Visibility.Visible)
            {
                TextBox tb = tbStartAngle;

                try
                {
                    int v = int.Parse(tb.Text);

                    if (0 <= v && v <= 360)
                    {
                        tb.Background = TrueBrush;
                    }
                    else
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbStartAngle_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VArc)
            {
                TextBox tb = tbStartAngle;

                try
                {
                    int v = int.Parse(tb.Text);

                    if (0 <= v && v <= 360)
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        (Parent as VArc).StartAngle = v;
                    }
                    else
                    {
                        if ((tb.Background as SolidColorBrush).Color == TrueColor)
                        {
                            tb.Background = ErrorBrush;
                            numError++;
                        }
                    }


                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "0";
                        (Parent as VArc).StartAngle = 0;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  EndAngle
        private void tbEndAngle_TextChanged(object sender, TextChangedEventArgs e)
        {
            TextBox tb = tbEndAngle;
            string result = "";

            foreach (var c in tb.Text)
            {
                int check = c - '0';

                if (check >= 0 && check <= 9)
                {
                    result += c;
                }
            }

            tb.Text = result.ToString();
            tb.CaretIndex = result.Length;
        }

        private void pEndAngle_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (pEndAngle.Visibility == Visibility.Visible)
            {
                TextBox tb = tbEndAngle;

                try
                {
                    int v = int.Parse(tb.Text);

                    if (0 <= v && v <= 360)
                    {
                        tb.Background = TrueBrush;
                    }
                    else
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }
                catch
                {
                    tb.Background = ErrorBrush;
                    numError++;
                }
            }
        }

        private void tbEndAngle_LostFocus(object sender, RoutedEventArgs e)
        {
            if (Parent is VArc)
            {
                TextBox tb = tbEndAngle;

                try
                {
                    int v = int.Parse(tb.Text);

                    if (0 <= v && v <= 360)
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        (Parent as VArc).EndAngle = v;
                    }
                    else
                    {
                        if ((tb.Background as SolidColorBrush).Color == TrueColor)
                        {
                            tb.Background = ErrorBrush;
                            numError++;
                        }
                    }


                }
                catch
                {
                    if (tb.Text.Trim() == "")
                    {
                        if ((tb.Background as SolidColorBrush).Color == ErrorColor)
                        {
                            tb.Background = TrueBrush;
                            numError--;
                        }

                        tb.Text = "90";
                        (Parent as VArc).EndAngle = 90;
                    }
                    else if ((tb.Background as SolidColorBrush).Color == TrueColor)
                    {
                        tb.Background = ErrorBrush;
                        numError++;
                    }
                }

                RefreshError();
            }
        }

        //  EmbossColor
        private void tbEmbossColor_LostFocus(object sender, RoutedEventArgs e)
        {
            string str = tbEmbossColor.Text.Trim();

            if (Parent is VImage)
            {
                if (str == "")
                {
                    (Parent as VImage).EmbossColor = null;
                }
                else
                {
                    (Parent as VImage).EmbossColor = str;
                }
            }
        }

        #endregion

        public void Connect(int connectionId, object target)
        {
            throw new NotImplementedException();
        }

        #region new

        private void btnOutline_Click(object sender, RoutedEventArgs e)
        {
            if (ly_Outline.Visibility == Visibility.Visible)
            {
                rOutline.Height = new GridLength(0);
                ly_Outline.Visibility = Visibility.Collapsed;
                btnOutline.Background = new SolidColorBrush(TrueColor);
            }
            else
            {
                rOutline.Height = new GridLength(1, GridUnitType.Star);
                ly_Outline.Visibility = Visibility.Visible;
                btnOutline.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6C13712A"));
            }
        }

        private void btnProperties_Click(object sender, RoutedEventArgs e)
        {
            if (ly_Properties.Visibility == Visibility.Visible)
            {
                rProperties.Height = new GridLength(0);
                ly_Properties.Visibility = Visibility.Collapsed;
                btnProperties.Background = new SolidColorBrush(TrueColor);
            }
            else
            {
                rProperties.Height = new GridLength(1, GridUnitType.Star);
                ly_Properties.Visibility = Visibility.Visible;
                btnProperties.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#6C13712A"));
            }
        }

        private void btnUp_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null || Parent == null || !(Parent is VGroupElement))
                return;

            if (parentGroup == null)
            {
                if (pos != 0)
                {
                    VObject temp = root[pos];
                    root.RemoveAt(pos);
                    root.Insert(pos - 1, temp);
                    RefreshOutline();
                    TreeViewItem item = TreeView.ItemContainerGenerator.Items[pos - 1] as TreeViewItem;
                    item.IsSelected = true;
                }
            }
            else
            {
                if (pos != 0)
                {
                    VObject temp = parentGroup.Elements[pos];
                    parentGroup.Elements.RemoveAt(pos);
                    parentGroup.Elements.Insert(pos - 1, temp as VGroupElement);
                    RefreshOutline();
                    TreeViewItem item = TreeView.ItemContainerGenerator.Items[int.Parse(pathPos[0]) - 1] as TreeViewItem;
                    item.IsExpanded = true;

                    for (int i = 1; i < pathPos.Length; i++)
                    {
                        if (i == pathPos.Length - 1)
                        {
                            item = item.ItemContainerGenerator.Items[int.Parse(pathPos[i]) - 2] as TreeViewItem;
                            item.IsSelected = true;
                        }
                        else
                        {
                            item = item.ItemContainerGenerator.Items[int.Parse(pathPos[i]) - 1] as TreeViewItem;
                            item.IsExpanded = true;
                        }
                    }
                }
            }
        }

        private void btnDown_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null || Parent == null || !(Parent is VGroupElement))
                return;

            if (parentGroup == null)
            {
                if (pos != root.Count - 1)
                {
                    VObject temp = root[pos];
                    root.RemoveAt(pos);
                    root.Insert(pos + 1, temp);
                    RefreshOutline();
                    TreeViewItem item = TreeView.ItemContainerGenerator.Items[pos + 1] as TreeViewItem;
                    item.IsSelected = true;
                }
            }
            else
            {
                if (pos != parentGroup.Elements.Count - 1)
                {
                    VObject temp = parentGroup.Elements[pos];
                    parentGroup.Elements.RemoveAt(pos);
                    parentGroup.Elements.Insert(pos + 1, temp as VGroupElement);
                    RefreshOutline();
                    TreeViewItem item = TreeView.ItemContainerGenerator.Items[int.Parse(pathPos[0]) - 1] as TreeViewItem;
                    item.IsExpanded = true;

                    for (int i = 1; i < pathPos.Length; i++)
                    {
                        if (i == pathPos.Length - 1)
                        {
                            item = item.ItemContainerGenerator.Items[int.Parse(pathPos[i])] as TreeViewItem;
                            item.IsSelected = true;
                        }
                        else
                        {
                            item = item.ItemContainerGenerator.Items[int.Parse(pathPos[i]) - 1] as TreeViewItem;
                            item.IsExpanded = true;
                        }
                    }
                }
            }
        }

        private void RefreshProperty_OutLine(VObject obj, bool exp = false)
        {
            List<int> path = GetPathByVObject(null, obj, null);

            if (path == null)
                return;

            TreeViewItem item = null;

            for (int i = 0; i < path.Count; i++)
            {
                if (path.Count == 1)
                {
                    item = TreeView.ItemContainerGenerator.Items[path[i]] as TreeViewItem;
                    item.IsSelected = true;
                    if (exp)
                        item.IsExpanded = true;
                }
                else if (i == 0)
                {
                    item = TreeView.ItemContainerGenerator.Items[path[i]] as TreeViewItem;
                    item.IsExpanded = true;
                }
                else if (i != path.Count - 1)
                {
                    item = item.ItemContainerGenerator.Items[path[i]] as TreeViewItem;
                    item.IsExpanded = true;
                }
                else
                {
                    item = item.ItemContainerGenerator.Items[path[i]] as TreeViewItem;
                    item.IsSelected = true;
                    if (exp)
                        item.IsExpanded = true;
                }
            }

            TreeView_SelectedItemChanged(null, null);
        }

        private List<int> GetPathByVObject(VGroup group, VObject obj, List<int> curPath)
        {
            if (group == null)
            {
                for (int i = 0; i < root.Count; i++)
                {
                    if (root[i] is VGroup)
                    {
                        List<int> cur = new List<int>();
                        cur.Add(i);

                        if (root[i] == obj)
                        {
                            return cur;
                        }

                        var result = GetPathByVObject(root[i] as VGroup, obj, cur);

                        if (result != null)
                        {
                            return result;
                        }
                    }
                    else if (root[i] is VShapeBase)
                    {
                        List<int> cur = new List<int>();
                        cur.Add(i);

                        if (root[i] == obj)
                        {
                            return cur;
                        }

                        for (int j = 0; j < (root[i] as VShapeBase).Elements.Count; j++)
                        {
                            if ((root[i] as VShapeBase).Elements[j] == obj)
                            {
                                cur.Add(j);
                                return cur;
                            }

                            if ((root[i] as VShapeBase).Elements[j] is VHandles)
                            {
                                for (int k = 0; k < ((root[i] as VShapeBase).Elements[j] as VHandles).Elements.Count; k++)
                                {
                                    if (((root[i] as VShapeBase).Elements[j] as VHandles).Elements[k] == obj)
                                    {
                                        cur.Add(j);
                                        cur.Add(k);
                                        return cur;
                                    }
                                }
                            }
                            else if ((root[i] as VShapeBase).Elements[j] is VFormulas)
                            {
                                for (int k = 0; k < ((root[i] as VShapeBase).Elements[j] as VFormulas).Elements.Count; k++)
                                {
                                    if (((root[i] as VShapeBase).Elements[j] as VFormulas).Elements[k] == obj)
                                    {
                                        cur.Add(j);
                                        cur.Add(k);
                                        return cur;
                                    }
                                }
                            }
                        }


                    }
                }

                return null;
            }
            else
            {
                for (int i = 0; i < group.Elements.Count; i++)
                {
                    if (group.Elements[i] is VGroup)
                    {
                        if (group.Elements[i] == obj)
                        {
                            curPath.Add(i);
                            return curPath;
                        }

                        List<int> cur = new List<int>();

                        for (int j = 0; j < curPath.Count; j++)
                        {
                            cur.Add(curPath[j]);
                        }

                        cur.Add(i);

                        var result = GetPathByVObject(group.Elements[i] as VGroup, obj, cur);

                        if (result != null)
                        {
                            return result;
                        }
                    }
                    else if (group.Elements[i] is VShapeBase)
                    {
                        if (group.Elements[i] == obj)
                        {
                            curPath.Add(i);
                            return curPath;
                        }

                        for (int j = 0; j < (group.Elements[i] as VShapeBase).Elements.Count; j++)
                        {
                            if ((group.Elements[i] as VShapeBase).Elements[j] == obj)
                            {
                                curPath.Add(i);
                                curPath.Add(j);
                                return curPath;
                            }

                            if ((group.Elements[i] as VShapeBase).Elements[j] is VHandles)
                            {
                                for (int k = 0; k < ((group.Elements[i] as VShapeBase).Elements[j] as VHandles).Elements.Count; k++)
                                {
                                    if (((group.Elements[i] as VShapeBase).Elements[j] as VHandles).Elements[k] == obj)
                                    {
                                        curPath.Add(i);
                                        curPath.Add(j);
                                        curPath.Add(k);
                                        return curPath;
                                    }
                                }
                            }
                            else if ((group.Elements[i] as VShapeBase).Elements[j] is VFormulas)
                            {
                                for (int k = 0; k < ((group.Elements[i] as VShapeBase).Elements[j] as VFormulas).Elements.Count; k++)
                                {
                                    if (((group.Elements[i] as VShapeBase).Elements[j] as VFormulas).Elements[k] == obj)
                                    {
                                        curPath.Add(i);
                                        curPath.Add(j);
                                        curPath.Add(k);
                                        return curPath;
                                    }
                                }
                            }
                        }
                    }
                }

                return null;
            }
        }

        private void btnNewFile_Click(object sender, RoutedEventArgs e)
        {
            if (root != null)
                root.Clear();

            Parent = null;
            parentGroup = null;
            pos = 0;
            pathPos = null;
            numError = 0;

            TreeView.Items.Clear();
        }

        private void TreeView_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (TreeView.Items.Count > 0)
            {
                (TreeView.Items[0] as TreeViewItem).IsSelected = true;
                (TreeView.Items[0] as TreeViewItem).IsSelected = false;
            }
        }

        private void AddShape_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VShape obj = new VShape();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VShape obj = new VShape();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddShapeType_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VShapeType obj = new VShapeType();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VShapeType obj = new VShapeType();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddLine_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VLine obj = new VLine();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VLine obj = new VLine();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddPolyLine_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VPolyLine obj = new VPolyLine();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VPolyLine obj = new VPolyLine();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddRect_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VRect obj = new VRect();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VRect obj = new VRect();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddRoundRect_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VRoundRect obj = new VRoundRect();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VRoundRect obj = new VRoundRect();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddOval_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VOval obj = new VOval();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VOval obj = new VOval();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddArc_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VArc obj = new VArc();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VArc obj = new VArc();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddCurve_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VCurve obj = new VCurve();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VCurve obj = new VCurve();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddImage_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VImage obj = new VImage();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VImage obj = new VImage();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddGroup_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem == null)
            {
                VGroup obj = new VGroup();

                if (root == null)
                    root = new List<VObject>();

                root.Add(obj);
                RefreshOutline();
            }
            else
            {
                VGroup obj = new VGroup();
                (Parent as VGroup).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VGroup).Elements[(Parent as VGroup).Elements.Count - 1]);
            }
        }

        private void AddPath_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VPath obj = new VPath();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddFormulas_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VFormulas obj = new VFormulas();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddHandles_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VHandles obj = new VHandles();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddFill_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VFill obj = new VFill();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddStroke_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VStroke obj = new VStroke();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddShadow_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VShadow obj = new VShadow();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddTextBox_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VTextBox obj = new VTextBox();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddTextPath_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VTextPath obj = new VTextPath();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddImageData_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VImageData obj = new VImageData();
                (Parent as VShapeBase).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VShapeBase).Elements[(Parent as VShapeBase).Elements.Count - 1]);
            }
        }

        private void AddF_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VF obj = new VF();
                (Parent as VFormulas).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VFormulas).Elements[(Parent as VFormulas).Elements.Count - 1]);
            }
        }

        private void AddH_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                VH obj = new VH();
                (Parent as VHandles).Elements.Add(obj);
                RefreshOutline();
                RefreshProperty_OutLine((Parent as VHandles).Elements[(Parent as VHandles).Elements.Count - 1]);
            }
        }

        private void TreeView_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Delete)
            {
                btnDelete_Click(null, null);
            }
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            if (TreeView.SelectedItem != null)
            {
                List<int> path = GetPathByVObject(null, Parent, null);

                if (path == null)
                    return;

                TreeViewItem item = null;

                if (path.Count == 1)
                {
                    root.RemoveAt(path[0]);
                    RefreshOutline();
                }
                else
                {
                    VObject pObj = root[path[0]];

                    for (int i = 1; i < path.Count - 1; i++)
                    {
                        if (pObj is VGroup)
                        {
                            pObj = (pObj as VGroup).Elements[path[i]];
                        }
                        else if (pObj is VShapeBase)
                        {
                            pObj = (pObj as VShapeBase).Elements[path[i]];
                        }
                    }

                    if (pObj is VGroup)
                    {
                        (pObj as VGroup).Elements.RemoveAt(path[path.Count - 1]);
                    }
                    else if (pObj is VShapeBase)
                    {
                        (pObj as VShapeBase).Elements.RemoveAt(path[path.Count - 1]);
                    }
                    else if (pObj is VHandles)
                    {
                        (pObj as VHandles).Elements.RemoveAt(path[path.Count - 1]);
                    }
                    else if (pObj is VFormulas)
                    {
                        (pObj as VFormulas).Elements.RemoveAt(path[path.Count - 1]);
                    }

                    RefreshOutline();
                    RefreshProperty_OutLine(pObj, true);
                }
            }
        }

        #endregion
    }
}